简体   繁体   中英

Setup Hibernate Session Factory in Tomcat

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM