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.  [ 5 posts ] 
Author Message
 Post subject: Concurrent database access
PostPosted: Wed Nov 12, 2003 1:18 pm 
Newbie

Joined: Wed Nov 12, 2003 8:40 am
Posts: 4
Location: Munich, Germany
What is the best solution for the following problem:

Two different processes (e.g. applications) are accessing the same record via
hibernate. Both processes are reading, modifing, and writing back the modified value.

Via the transaction isolation level I can ensure that the changes
are only visible after the commit.

But how can I ensure that both processes are not reading stale data.

E.g. that the following won't happen:

Process A and B reading the same value (e.g. 10)
Process A is increasing the value to 11
Process A is committing
Process B is decreasing the value to 9
Process B is committing

Just transactions aren't enough.

The last wins, the value is now 9, instead of 10.

What would be the "best hibernate practice"?

Thanks in advance,
Dieter Bogdoll


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 1:59 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Hibernate can help with locking, but it is more about shema design.
All OLTP systems I have ever saw are implemented without locking.

http://forum.hibernate.org/viewtopic.ph ... 5&start=15

This problem becomes more "interesting" if your app moves something like money in bank.

Forget "nice" OOP style persistence with "saveorupdate" sometimes.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 9:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a Hibernate <version> property, whcih avoids this kind of problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 6:47 am 
Newbie

Joined: Wed Nov 12, 2003 8:40 am
Posts: 4
Location: Munich, Germany
Hi Gavin,

[quote="gavin"]Use a Hibernate <version> property, whcih avoids this kind of problem.[/quote]

That's a good solution to my problem.

Did I overlooked this problem in the FAQs?
If it is missing in the FAQ, this topic should really be mentioned there.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 9:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You overlooked the reference guide section 14.3

_________________
Emmanuel


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