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: merge and optimistic locking exceptions
PostPosted: Thu Feb 07, 2008 7:16 pm 
Newbie

Joined: Thu Feb 07, 2008 11:19 am
Posts: 2
After upgrading to hibernate 3 our company substituted the merge call for saveorupdateCopy (we called saveorupdateCopy whenever we were updating a record). The problem is that merge does not throw the optimistic locking exception. Substituting update for saveorupdatecopy has caused all sorts of problems with NonUniqueObjectExceptions even though I am calling evict on the object before calling update.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 11:02 pm 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
does this doc help any...

http://www.jroller.com/RickHigh/entry/hibernate_3_merge

I struggled with merge vs. saveOrUpdate myself a while back on similar issues.

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 2:18 pm 
Newbie

Joined: Thu Feb 07, 2008 11:19 am
Posts: 2
That was helpful although it didn't sole our problem. Basically, our application works almost exclusively with detached objects. And object is retrieved in one session sent out to the front end in DTO form, edited by a user, and submitted back for persistence in a new session. Inside this new session almost all of our updates a predicated by looking the incoming object up in the database, thus populating the hibernate cache.

When we submit the incoming record for persistence with the merge call, what we were seeing is that the merge overwrote the version field of the incoming record, with the version of the record just looked up in the cache. This makes sense from what I've read. The problem is that it breaks our concurrent update checking and when flush is called, no optimistic lockeing exceptions are thrown (which again makes sense, the version field is correct thanks to the merging of the incoming detached object with the recently looked up object).

So the way I solved it was to write my own custom MergeEventListener. My listener waits for a merge, checks the cache for a record, if it is there, I compare the version of the incoming record against the cached version and throw my own optimistic locking exception. If there are no problems then is imply pass the data onto the DefaultMergeEventListener provided by hibernate.


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.