1

I have been reading around the Hibernate core and I am still exploring some of its capability.

It was mention in the docs that the SessionFactory is the heavyweight component of Hibernate thus it should be setup only once in a web application and in singleton. Each Session factory should pertain to one JDBC connection.

Does anybody knows how to properly setup the session factory in tomcat web applications? Any links or tutorials would be better.

Should I set it up as a contextlistener class also?

Thanks.

Mark Estrada
  • 9,013
  • 37
  • 119
  • 186

1 Answers1

6

Here is the recommendation from Hibernate website itself on configuring Hibernate with Tomcat. Also your statement "Each Session factory should pertain to one JDBC connection." is wrong. The factory is created once and cached. It can then be used to create "Session"'s that are kind of wrapper on a JDBC connection and in a way can be thought as analogous to the JDBC connection.

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • Thanks for clearing my thoughts. Just one question though. What's in this line of code HibernateUtil.getSessionFactory()? It is in the contextInitialized method? This is actually the code that I am looking for. – Mark Estrada Jan 03 '11 at 04:50
  • It is a utility class. Read more details here under "1.1.6. Startup and helpers" section http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html – Aravind Yarram Jan 03 '11 at 05:34