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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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

Hibernate : How a real hibernate project is configured

Vishal Bhatnagar

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.


Bill Gorder

Joined: Mar 07, 2010
Posts: 1648

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.
3)Spring has annotation based declarative transaction support using @Transactional

As far as caching goes hibernate has caching options in addition Spring has a caching abstraction as well

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

Joined: Sep 15, 2012
Posts: 2
Thanks Bill !
I agree. Here's the link: http://aspose.com/file-tools
subject: Hibernate : How a real hibernate project is configured