• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate : How a real hibernate project is configured

 
Vishal Bhatnagar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vishal Bhatnagar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic