-->
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: performance degradation with hibernate collection
PostPosted: Mon Feb 02, 2009 2:52 pm 
Newbie

Joined: Mon Feb 02, 2009 2:30 pm
Posts: 2
Location: Bangalore
Hi Experts, i have a performance issue in my application.
i am using hibernate 3.

here is description of the issue
i have a hibernate parent object and it has a set child object (collection)
single parent could have 20,000 children

i read the parent and get all the child objects into a collection
now i iterate over each child object in a for loop and update and save the object and commit...

first iteration : update the first child and commit --2 updates are fired to database- one for parent object and one for child object that was modified

second iteration: update the second child and commit --3 updates are fired to databse - one for parent object, one for the first child and one for the second child

note that though i have not modified the first child object in the second iteration, hibernate still fires an update to the first child object also......this becomes very expensive when i have 20,000 child objects. at the end of 20,000 iteration it would fire 20,000 updated to the database while i have only modified the last child record


how to solve this issue. pls help

Thanks
Raghav


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 3:25 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Try to make it more like batch updates. Try to update like 20 at a time, then flush and clear after each group.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 3:43 pm 
Newbie

Joined: Mon Feb 02, 2009 2:30 pm
Posts: 2
Location: Bangalore
kochcp wrote:
Try to make it more like batch updates. Try to update like 20 at a time, then flush and clear after each group.


hello chris, thanks for quick reply.
i can do a batch update because on every iteration i modify a child object and perform some processing and update date column value of the child object and commit. this is an indication for me that iteration went fine without failure.
if i go for batch updates and commit in batch size of say 10 .... then in the middle of 5th iteration to say, i get an exception and i have to rollback then i will be rolling back the entire 10 records which is not correct.

to solve my issue i have to update only the child object that i am iterating.
is their a way i can do that

Thanks
Raghav


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 5:04 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
try a flush and clear after each single child then

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.