This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JDBC and the fly likes locking and unlocking mechanism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "locking and unlocking mechanism" Watch "locking and unlocking mechanism" New topic

locking and unlocking mechanism

Joseph Tsui

Joined: Jan 05, 2002
Posts: 6
Hi All,

I am trying to implement a client program that can obtain record from MSSQL. I am using hibernate to do that.

So client A and client B will get record from DB server
both client A and B are on different machines

How can i prevent the situation that

ClientA get
ClientB get
ClientA update
ClientB update

In the database, i have a retrieve flag for each record. once the client get the record, it will update the record with the retrieve flag = true

Anyone can provide me advice on that? thanks a million
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Have a google (or a search in these forums) for "optimistic locking" - this is techique usually used to solve the lost update problem. Also, have a read of the Hibernate documentation about versioning, which is Hibernate's optimistic locking implementation.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: locking and unlocking mechanism
Similar Threads
Why I lost points in locking, pls comment on my code
Lock Operation
pass scjd, graded in 4 days.
URLyBird: how to calculate clientId
Synchronization of ServletContext Object.