-->
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: save() increments version even if instance is not dirty
PostPosted: Thu Apr 13, 2006 4:59 pm 
Beginner
Beginner

Joined: Wed Sep 28, 2005 5:30 pm
Posts: 25
Hibernate version: 3.1.3

I noticed that if I save(foo) its version number is incremented even if it has never been changed (its setters have never even been invoked). This causes concurrency problems because I get StaleObjectStateException even if no data is actually stale.

I have cascade="save-update" set which is triggering save(foo) so I don't really control this. I expect foo to be saved to the DB if it does not already exist there, update in the DB if it has been changed, and nothing to happen if it is not dirty and already exists in the DB.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 5:54 pm 
Beginner
Beginner

Joined: Wed Sep 28, 2005 5:30 pm
Posts: 25
I believe this is a bug.

If PersistentSet.add() is invoked on an element which is already in the Set and the Set is initialized then isOperationQueueEnabled() will return false, exists will be set to null and then the code will mark the Set as dirty even though it already contains the element. I believe a quick fix would be to modify the first line of code from:

if (exists==null) {
write();
return set.add(value);
}

to:

if (exists==null) {
boolean result = set.add(value);
if (result) {
write();
}
return result;
}

I have tested this locally and it fixes the problem for me. I posted http://opensource.atlassian.com/project ... e/HHH-1668 to this effect.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 14, 2006 9:49 pm 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
Have you tried select-before-update in your mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 14, 2006 10:49 pm 
Beginner
Beginner

Joined: Wed Sep 28, 2005 5:30 pm
Posts: 25
DWright wrote:
Have you tried select-before-update in your mapping?


No, I did not try select-before-update. The benefit of the above fix is that it fixes the problem *without* the negative performance impact associated with select-before-update.

Thanks for the idea though!


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.