-->
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.  [ 1 post ] 
Author Message
 Post subject: Optimistic Locking Issue
PostPosted: Tue Sep 29, 2009 3:37 pm 
Newbie

Joined: Tue Sep 29, 2009 2:45 pm
Posts: 1
We have a web app using Hibernate 3.2.6 that uses automatic versioning for all objects using a timestamp as the version attribute. We have two cases where we consistently get StaleObjectStateExceptions when we know we are the only user accessing a particular piece of data. The exceptions are thrown when Hibernate tries to flush an object that has been modified in the current session more than once. That is, the flow is:

1. Object loaded from database.
2. Object modified.
3. Object flushed automatically by Hibernate in preparation for a query on another object class.
4. Object modified some more.
5. Attempt to flush object gets StaleObjectStateException, as we prepare to do another query on a different object class.

So, I conclude that the first flush updates the version (timestamp), and the second flush fails because it reads the database value for the version, not the one already in the session.

This same pattern fails if steps 1 and 2 are a new object creation and save, as opposed to a load of an existing object.


This doesn't seem like proper behavior to me. Shouldn't the version check use the value for the object that's in the session, instead of looking to the database to do its check?

Any suggestions for a work around?

Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.