-->
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: What alternatives to select-before-update are there?
PostPosted: Wed Jan 21, 2009 8:45 pm 
Regular
Regular

Joined: Wed Jan 21, 2009 8:41 pm
Posts: 54
At work we are using hibernate 3.2.2ga and I'm wondering what are the alternatives to select-before-update? We have an issue with a to-many relationship where a transaction commit takes forever as more objects are added to the too many side of the relationship. This is more than likely caused by the select-before-update that it's doing when it queries one select at a time ever single object back on the to-many side.

I'm aware of alternatives such as keeping the original state or snapshot of the object around in memory or making use of a version field or timestamp.

Are there alternatives to select-before-update in releases of hibernate since 3.2.2ga?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 3:44 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You could merge your root object before updating it. If you want all referenced objects to be merged, you can either set fetch-strategy to eager, or even better use CascadeType.MERGE, so that the merge-operation is cascaded to the relationship.

Maybe enabling batch-fetching is also a solution, but I am not sure in this case. To enable batch-fetching you have to enable it via hibernate-configuration (set hibernate.jdbc.batch_size and hibernate.default_batch_fetch_size).

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 12:40 pm 
Regular
Regular

Joined: Wed Jan 21, 2009 8:41 pm
Posts: 54
So you're saying that when you do the merge operation I wouldn't be incurring overhead I'm already incurring with select-before-update?

We use ehcache but our Session open/closes all the time and I assume this rules on lazy fetching with ehcache. I'm curious as to why ehcache cannot reattach the object with the session.

mmerder wrote:
You could merge your root object before updating it. If you want all referenced objects to be merged, you can either set fetch-strategy to eager, or even better use CascadeType.MERGE, so that the merge-operation is cascaded to the relationship.

Maybe enabling batch-fetching is also a solution, but I am not sure in this case. To enable batch-fetching you have to enable it via hibernate-configuration (set hibernate.jdbc.batch_size and hibernate.default_batch_fetch_size).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 12:52 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I think if you use merge, the whole collection of the toMany-relationship is going to be fetched in a single statement instead of selecting each entry. But I am just guessing, have you tried it? Also, you should try to enable batch-fetching.

_________________
-----------------
Need advanced help? http://www.viada.eu


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.