-->
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: Strategy for dealing with objects that may be out of date?
PostPosted: Wed Dec 17, 2003 2:04 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
Hi I am using Struts with Hibernate in a webapplication.. we are using forms etc. The problem I am currently trying to decide how to handle is thus:

Assume user 1 loads up an object in a form and is modifying it.
Assume user 2 loads up the same object in a form and is also modifying it.
User 1 submits the modified object.
User 2 also submits the object, however his is out of date and I would like the webapp to tell him that and show the differences that exist.

What is the best way to use hibernate to deal with this? What I have attempted is using the built in timestamp feature in MySQL, I have a field in my object that is timestamp but does not insert or update, thus mysql controls its value. Then when the user submits the object I loaded another copy of that object from the DB and tried to compare their dates.. however this gave me an error saying:

net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 1, of class: cmcflex.salesweb.model.prospect.Prospect

because of the object I loaded to compare.

What do do? Is there a better strategy for tackling this? I tried using the actual <timestamp> in the properties for my object, but then when I tried to submit the object the generated sql said "when id=? AND timestamp=?" meaning it would not update if the timestamp is different, and I'm unsure if I could even determine if it did or did not update.

Thanks in advance,
David


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just use <timestamp> or <version> and catch the StaleObjectException you will get when trying to update an outdated object


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 2:18 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
Ok great, I'll give that a try.
Thanks,
David


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.