-->
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.  [ 2 posts ] 
Author Message
 Post subject: DAO: how to avoid lost update?
PostPosted: Fri Jul 02, 2004 5:29 am 
Newbie

Joined: Wed Jun 16, 2004 9:54 am
Posts: 7
Hello!

When I abstract from Hibernate using the DAO Pattern, how can I avoid a lost update? For example I execute the following steps:

1. I call a "read" DAO method, which uses Hibernate to load the data I need from the database and gives me back a DTO.
2. I do something with this data and modify it.
3. I write it back by calling an "update" DAO method, which again uses Hibernate to make the changes persistent.

If I have two users, which execute these steps in parallel, I could end up with a lost update. One solution would be to implement my own optimistic locking, but isn't there a better way where I can use the optimistic locking of Hibernate? Or a different pattern?

Thank you very much for any suggestions or links,
Jonas

P.S.: I posted a similar question on theserverside, but I thought maybe someone here had the same problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 5:59 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Map a version column and use Hibernate's automatic versioning (or better, in your case, use the same database transaction for both DAO calls if there is no "long" time in between). Check the documentation, chapter about Transactions.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.