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.
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?).