-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: OutOfMemory. Hibernate
PostPosted: Sun May 18, 2008 6:46 pm 
Newbie

Joined: Fri Mar 07, 2008 5:32 pm
Posts: 6
Hibernate version: Last one

Code between sessionFactory.openSession() and session.close():

Code:
   public static Object createSession() throws Exception {
      Session session = (Session) currentSession.get();
      Owner id = null;
      System.out.println(session);
      if (session == null) {
         System.out.println("No Session Found - Create and give the identity");
         session = getSessionFactory().openSession();
         currentSession.set(session);
         id = trueOwner;
      } else {
         System.out.println("Session Found - Give a Fake identity");
         id = fakeOwner;
      }
      sessions.add(session);
      return id;
   }


Code:
   public static void closeSession(Object ownership) throws Exception {
      if (((Owner) ownership).identity) {
         System.out.println("Identity is accepted. Now closing the session");
         Session session = (Session) currentSession.get();
         session.flush();
         session.clear();
         session.close();
         currentSession.set(null);
      } else {
         System.out.println("Identity is rejected. Ignoring the request");
      }
   }


Full stack trace of any exception that occurs:
OutOfMemory

Name and version of the database you are using:
Oracle 9


OK, after fighting against an OutOfMemory exception all the weekend, I come to you, experts to help me with my case, I have tried a lot of things but no success, after using JProbe I could do the follow test:
1. Stress test for 10 minutes (Using SOAPUI, yes, I'm developing a WebService)
2. I invoke a Garbage Collector and take a snapshot of current loaded classes

The result, sorting by memory usage is:

Code:
Package                     Class        Count             Memory
                            char [ ]  68,278 (13.6%)       22,685,896 (66.2%)
java.lang                   String [ ]  157,285 (31.3%)    2,663,576 (7.8%)
java.lang                   String  69,132 (13.7%)         1,659,168 (4.8%)
org.hibernate.loader.entity EntityLoader  9,750 (1.9%)     858,000 (2.5%)
java.util                   HashMap$Entry  32,316 (6.4%)   775,584 (2.3%)
java.util                   HashMap$Entry [ ]  7,535 (1.5%) 718,128 (2.1%)
java.lang                   String [ ] [ ]  12,240 (2.4%)  635,760 (1.9%)
java.lang.reflect           Method  6,798 (1.4%)           543,840 (1.6%)
org.hibernate.loader        DefaultEntityAliases  10,200 (2.0%)  408,000 (1.2%)
java.util                   HashMap  7,535 (1.5%)          301,400 (0.9%)
                            int [ ]  6,778 (1.3%)          183,112 (0.5%)
                            boolean [ ]  9,210 (1.8%)      177,000 (0.5%)
org.hibernate.persister.entity  Loadable [ ]  10,200 (2.0%)  163,200 (0.5%)


OK, I believe that the first classes are being used by the next one, in this case I could check that EntityLoader Class is not being collected by GC.

Could someone help me to ensure that all my hibernate objects are being closed, so, I believe that I could fix this OutOfMemory error.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 6:57 pm 
Newbie

Joined: Fri Mar 07, 2008 5:32 pm
Posts: 6
I've found the memory leak tracing hibernate class, my webservice was loading everytime the method:

sessionFactory = new Configuration().configure().buildSessionFactory();

Now everything is ok.
cya


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 9:51 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Ouch! You don't want to be making that call every time, that's for sure!

Glad you solved your problem, and thanks for reporting back.

-Cameron McKenzie

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.