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.  [ 4 posts ] 
Author Message
 Post subject: Fetching records in batches using hibernate
PostPosted: Wed Oct 03, 2007 3:53 am 
Newbie

Joined: Tue Oct 02, 2007 10:42 am
Posts: 10
Hi All,

I am using Hibernate to query a table having more than 200000 records.
I used the session.createCriteria(<classname>).list() method. However this causes a ava.lang.OutOfMemoryError: Java heap space exception.

Is there any way in hibernate that i can read data in batches? i.e. read about 100 records, process them and then read the next 100 records?

Any help would be appreciated.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 4:11 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Is it so hard to look at manual first ;-).

http://www.hibernate.org/hib_docs/v3/re ... batch.html

Regards,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 4:21 am 
Newbie

Joined: Tue Oct 02, 2007 10:42 am
Posts: 10
Thanks for pointing it out. However, the manual gives the process for handling only batch inserts and updates. I am facing the porblem for a select when i use Criteria.list(). Any points on that?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 4:45 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Well yes, ok, see this:

http://forum.hibernate.org/viewtopic.php?t=980052

Also don't forget to do flush and clear in the cycle to clear the session-level cache.

Regards,
Pavol


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