-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Fri Jun 05, 2009 11:59 am 
Newbie

Joined: Fri Jun 05, 2009 11:21 am
Posts: 2
We are working on a new implementation and the project requires us to process bulk data. Some scenarios of data processing are mentioned below.
1) We have around 10-12 million records in the tables on which our processes run.
2) The select criteria to process a set of records fetches minimum 45-50K records. Some scenarios bring in upto 100K records.There is no way we can break up this based on the business requirement.

Our approach and issues in this approach we are facing are mentioned below
1) We are using Hibernate's Core Criteria to fetch the records. We get an outOfMemory/heap size exception when the number of records found are more than 25K inspite of setting the following property to increase the JVM heap size -XX:MaxPermSize=512M -Xms512m -Xmx512m
2) We have tried setting the following properties to set the hibernate.jdbc.batch_size as well but it doesnt resolve the issue :
<prop key="hibernate.jdbc.batch_size">20</prop>
3) We have tried to set the second level cache to false but of no use
<prop key="hibernate.cache.use_second_level_cache">false</prop>
4) We set the property to use scrollable result set but of no use
<prop key="hibernate.hibernate.jdbc.use_scrollable_resultset">false</prop>

I have following questions :
1) Is it really advisable to use Hibernate or even hql to handle such large volume of data or it is better to use the native SQL in such scenarios.
2) Does anyone have specific instances to quote who have handled/processed such large volumes of data using hibernate.
3) Do we have any suggestions/best practices/recommendations for handling such large volume of data.


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Fri Jun 05, 2009 6:46 pm 
Beginner
Beginner

Joined: Mon Jun 01, 2009 5:39 am
Posts: 34
You say you use the native Hibernate API.

When you query for those 50k+ rows, do you use Projections to limit the number of columns returned from the underlying table(s), or do you return all columns each time because you don't have a choice?


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Fri Jun 05, 2009 10:44 pm 
Newbie

Joined: Fri Jun 05, 2009 11:21 am
Posts: 2
In actual, the table which we are trying to query has around 30 columns. Just to try this out, we mapped just 10 columns of the table to our entity object. This is the most simple case when we are trying to read data from just one table. Just to summarize,we just get the columns we need and not all the columns of the tables. The select criteria does not even involve a join to another table. Have you tried getting 50K+ records using hibernate?


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Sat Jun 06, 2009 6:31 pm 
Beginner
Beginner

Joined: Mon Jun 01, 2009 5:39 am
Posts: 34
After looking a little more at the API (and the Hibernate user guide), I've seen that you can limit the result set size by using two methods, valid both for the Criteria (or DetachedCriteria) API and for the Query API: setFirstResult() and setMaxResults(). Both take an integer as an argument. Beware, it starts at 0, not 1.

Also, you can use .iterate() in both cases as well, if you can afford to iterate over the results.


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Thu Jul 16, 2009 10:26 am 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
I was always told to avoid Hibernate, i.e., use direct JDBC API, for that many number of records (more than 100,000).

Am also aware of something called StatelessSession, which I believe gives you better performance in case you have used Hibernate AND that you will not bring or deal with collections and relationships and then there is batching, which has to be used by you, I believe, to avoid dealing with all the records at the same time and hence avoid memory issues!

I will update you more when I use the StatelessSession and you do keep posting your solutions even if you don't come across better ideas!

Regards
Krishna


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Thu Jul 16, 2009 10:33 am 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Hibernate_reference Ch13. Batch processing has it all!!!

All the best.

Regards
Krishna


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Fri Jul 17, 2009 8:38 am 
Regular
Regular

Joined: Tue Oct 10, 2006 2:21 pm
Posts: 58
pvradhakrishna wrote:
Am also aware of something called StatelessSession, which I believe gives you better performance in case you have used Hibernate AND that you will not bring or deal with collections and relationships and then there is batching, which has to be used by you, I believe, to avoid dealing with all the records at the same time and hence avoid memory issues!

I will update you more when I use the StatelessSession and you do keep posting your solutions even if you don't come across better ideas!



Except that, apparently, you can't use StatelessSessions with classes that contain a Collection member that is mapped with lazy="false".

I believe that to be the case, although I haven't yet confirmed it. I have an open topic in this forum on that subject: https://forum.hibernate.org/viewtopic.php?f=1&t=998373. If anyone knows the way around this, I'd love to hear it either here or there.


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Sat Jul 18, 2009 12:24 am 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
:) Already faced this issue while testing, here is the patch discussed at
https://forum.hibernate.org/viewtopic.php?f=1&t=957223

the patch is at
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3220


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Sat Jul 18, 2009 8:19 am 
Regular
Regular

Joined: Tue Oct 10, 2006 2:21 pm
Posts: 58
pvradhakrishna wrote:
:) Already faced this issue while testing, here is the patch discussed at
https://forum.hibernate.org/viewtopic.php?f=1&t=957223

the patch is at
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3220


Interesting. In your case you could still make your StatelessSession query involving an object with lazy=false, ultimately resulting in a threading issue, whereas in my case, a much simpler query, it immediately refused to make the query giving the exception I mentioned in my thread.

In my case the solution was simple: to remove the lazy=false and rewrite the three dao methods that ever fetched this object to dynamically fetch eagerly (setFetchMode or access the collection).

I begin to believe that lazy=false is actually the "lazy man's way to do eager fetching" and should be avoided if at all possible.


Top
 Profile  
 
 Post subject: Re: Hibernate : Handling Bulk Records in Batch Processing
PostPosted: Sun Jul 19, 2009 12:08 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Quote:
I begin to believe that lazy=false is actually the "lazy man's way to do eager fetching" and should be avoided if at all possible.


Ha haa :), exactly, the same thing was ringing in my mind, it is never too late!

Regards
Krishna


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