aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate : How a real hibernate project is configured Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate : How a real hibernate project is configured" Watch "Hibernate : How a real hibernate project is configured" New topic
Author

Hibernate : How a real hibernate project is configured

Vishal Bhatnagar
Greenhorn

Joined: Sep 15, 2012
Posts: 2
Hi ,
I have recently joined JavaRanch in order to seek help from the tech geeks here. I have been given responsibility build an application using Hibernate and Spring.
I have only bookish knowledge of hibernate so I wanted to know few things :
(1) How in a real project the datasource is configured. We have several different environments each using a different database. So the datasource configuration needs to be flexible.
(2) How to configure a SessionFactory in a real project. I don't want any Java code to be written like to create a new Configuration object and calling the buildSessionFactory() method to
get the SessionFactory. How does in a real project a Session Factory is configured ?
(3) What are other configurations need to be set , i mean to say how to handle transaction strategy, caching and other stuff.

Can somebody please enlighten on these things ? It would be great if someone can share the WAR of a real project so that I can see other things as well.

Thanks


Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Spring makes this pretty easy.

1) Typically datasources are managed by the container and your application will obtain a reference through a jndi lookup. If you have multiple configurations have a look at Spring profiles.
2) I would go with JPA if you can. If you need hibernate specific annotations you can still use them. See the reference documentation.
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/orm.html#orm-jpa
3)Spring has annotation based declarative transaction support using @Transactional
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/transaction.html#transaction-declarative-annotations

As far as caching goes hibernate has caching options in addition Spring has a caching abstraction as well
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/cache.html#cache-annotations


[How To Ask Questions][Read before you PM me]
Vishal Bhatnagar
Greenhorn

Joined: Sep 15, 2012
Posts: 2
Thanks Bill !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate : How a real hibernate project is configured