I'm experiencing a OutOfMemory error from Tomcat. This error started ever since I added Hibernate into the application. I'm not using Spring, so I do all the open/close for Hibernate Sessions.
Below are a few Hibernate configs that I'm using. I create my SessionFactory in the Java code.
hibernate.current_session_context_class=thread
hibernate.connection.jndi.datasource=jdbc/dataSource
I created my own HibernateUtil class to retrieve/save data. To initialize this I just call the MyHibernateUtil.initialize() and will create the SessionFactory.
This is basic application with one Servlet. This was not an issue until Hibernate was added. I'm also closing the session using MyHibernateUtil.closeSession() from below.
Anyone faced Tomcat OutOfMemory issues using Tomcat and Hibernate?
public class MyHibernateUtil{
public static SessionFactory factory = null;
public static AnnotationConfiguration aConfigure = new AnnotationConfiguration();
private static AnnotationConfiguration configure(){
//Add my annotated classes here
...
return aConfigure;
}
public static initialize(){
Configuration configure = MyHibernateUtil.configure();
//I add my Hibernate configuration stuff here.
factory = configure.buildSessionFactory();
}
public static Session getSession(){
Session hibernateSession = factory.getCurrentSession();
return hibernateSession;
}
public static void closeSession(){
MyHibernateUtil.getSession().close();
}
public static Session beginTransaction() {
Session hibernateSession;
hibernateSession = MyHibernateUtil.getSession();
hibernateSession.beginTransaction();
return hibernateSession;
}
public static void commitTransaction() {
MyHibernateUtil.getSession().getTransaction().commit();
}
}