Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where do I initialize and store Hibernates SessionFactory

 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a web application using tomcat 5 and hibernate. However, I am unsure about the creation and initialization of SessionFactory.

Do I create the SessionFactory once at startup and then store it in the Servlet context? Or is it ok to initialize the SessionFactory with each request? (This does not sound right).

I am using HibernateUtil. The initialization of the SessionFactory is in the static block. Does this mean that the SessionFactory is only every initialized once or does it mean it is initialized each time a new thread accesses it? i.e. local thread.

Thank you for your help.
david
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Configuring a SessionFactory is a big job, so only do it once. It doesn't make any sense to do this for every request; your data model will remain pretty static. I don't know how your HibernateUtil class will do it (where is it from?).
 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using HibernateUtil.java which is found on the Hibernate web site.

Regards

David
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic