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: saveOrUpdate for a list of 5000 or more objects or batch Upd
PostPosted: Fri Jan 22, 2010 3:55 am 
Newbie

Joined: Fri Dec 04, 2009 5:10 am
Posts: 14
Hi guys,
I am reading a file which is exact replica of database table. I read each line and convert it into an object and place it in a list. After this, I call the saveOrUpdate() function on each object by iterating over the list. So that if there is any change in the file that is updated in database too.

Now I need to know if there is any performance efficient way of doing so in hibernate so that the whole list is updated into the database, because at times I can have more than 10000 records. Hope you guys understand what I explained.


Top
 Profile  
 
 Post subject: Re: saveOrUpdate for a list of 5000 or more objects or batch Upd
PostPosted: Fri Jan 22, 2010 7:07 am 
Beginner
Beginner

Joined: Thu Oct 04, 2007 12:22 pm
Posts: 48
Hello,

I have some sugegstions, but you have to decide on your task, which one will fit best.
First of all, when you do batch processing you will soon encounter problems with the
actual Session. My experiences are, that hibernate works quite performant to a certain
point of data and then the performance crashes (or you will get memory problems).

So if you use a standard session you will need to flush and evict objects regulary. There
is a guid for batch processing in the manual discussing this step.

If you can disclaim a normal session and do not need the caching algorithm behind it,
you can use a StatelessSession. This will give you no real advantage in terms of speed,
but you will not have to care about the session producing memory problems (because
the entities will not be attached). I have done a batch processing just some time ago
and it worked very good.


Top
 Profile  
 
 Post subject: Re: saveOrUpdate for a list of 5000 or more objects or batch Upd
PostPosted: Fri Jan 22, 2010 11:45 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quite often, these one-off type tasks can be written without using Hibernate, and can be optimized just with SQL. Part of the beauty of Hibernate is that it greatly simplifies development and program maintenance. If it's a relatively simple script, the Hibernate benefit might be minimal.

_________________
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.