public class HibernateListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
HibernateUtil.getSessionFactory(); // Just call the static initializer of that class
}
public void contextDestroyed(ServletContextEvent event) {
HibernateUtil.getSessionFactory().close(); // Free all resources
}
}
This is configured in web.xml and loaded via my initialServlet. Problem is how do I get sessions in my DAO classes?
Let me know if more info is required.
Not sure what this HibernateUtil is doing exactly, but usually you create a Session from a SessionFactory by calling openSession on the SessionFactory, so you would do SessionFactory#openSession()