views:

39

answers:

1

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();
  }

}
+1  A: 

Well, perhaps your memory is not sufficient to load everything. Increase it in catalina.sh by adding -Xmx256m and -XX:MaxPermSize=128m to the CATALINA_OPTS variable. (my numbers are chosen arbitrarily). (You can also set initial values with -Xms)

Bozho
Yeah I'm giving this a try. thanks.
Marquinio