-->
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.  [ 6 posts ] 
Author Message
 Post subject: Another java.lang.OutOfMemory
PostPosted: Tue Jan 18, 2005 11:54 am 
Newbie

Joined: Mon Dec 06, 2004 5:51 am
Posts: 8
Location: Istanbul/Turkiye
Hibernate version: 2.1.6

Name and version of the database you are using: Oracle 10g

Mapping documents:
Code:
<class name="Category" table="CATEGORY">
   ...
   <property name="name" column="CATEGORY_NAME"/>
   <many-to-one
      name="parentCategory"
      class="Category"
      column="PARENT_CATEGORY_ID"
      cascade="none"/>
   <list
      name="childCategories"
      table="CATEGORY"
      cascade="all"
      inverse="true">
         <key column="PARENT_CATEGORY_ID"/>
     <index column="CATEGORY_CODE"/>
     <one-to-many class="Category"/>
   </list>
   ...
</class>

There are ~ 17500 total categories (actually it is not category in our application, I use category because there is a sample in Hibernate in Action like this, only difference is there was a set instead of list). When we try to load categories we always get "java.lang.outofmemoryerror". I know someone will send reply like
"Don't load all the table to session!".
But we are getting them to put into a dictionary to lookup in runtime (it will be used a lot and we don't want to go to database every time). We tried ScrollableResults and clearing session after every 20 category but result is same.

Is there a solution to this outofmemory problem?

Note: We searched the forum and read related posts (those we could find)

_________________
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 2:00 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Try the approach mentioned in this blog:

http://blog.hibernate.org/cgi-bin/blosx ... batch.html

Basically, when you're iterating over large numbers of objects, you periodically need to flush and clear the session to prevent the caches from overflowing. As you can see in the blog posting, there is a very good reason for this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 2:03 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
In case the blog goes away or moves, just so the archive has the code, it goes something like:

Code:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

ScrollableResults customers = session.getNamedQuery("GetCustomers")
   .scroll(ScrollMode.FORWARD_ONLY);
int count=0;
while ( customers.next() ) {
   Customer customer = (Customer) customers.get(0);
   customer.updateStuff(...);
   if ( ++count % 20 == 0 ) {
      //flush a batch of updates and release memory:
      session.flush();
      session.clear();
   }
}

tx.commit();
session.close();


Top
 Profile  
 
 Post subject: clear Hibernate cache
PostPosted: Tue May 17, 2005 12:11 pm 
Newbie

Joined: Wed Feb 09, 2005 12:00 pm
Posts: 2
Is there a way to programatically disable the cache. I don't want any objects cached while I perform bulk operations as the cache causes me more trouble than it is worth.

_________________
Suzanne
"Reality is merely an illusion, albeit a very persistent one." - Einstein


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:06 am 
Newbie

Joined: Wed May 11, 2005 5:39 am
Posts: 9
try StatelessSession (has no persistence context )


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:40 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Use lazy="true" in list element.


Amila
(Rate if helps)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.