wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Optimistic concurrency in hibernate using version/timestamp. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Optimistic concurrency in hibernate using version/timestamp." Watch "Optimistic concurrency in hibernate using version/timestamp." New topic

Optimistic concurrency in hibernate using version/timestamp.

sharath kumar reddy karnati

Joined: Jul 23, 2007
Posts: 5
Hi All,

I didn't understand how optimistic concurrency will work in hibernate?

As per my knowledge, we need to have either VERSION or TIMESTAMP column in persistence table which is mappend to hibernate.

Say we are having TIMESTAMP column then whenever we execute INSERT,UPDATE statement hibernate will modify TIMESTAMP column with system timestamp. When we try to update a row and that row timestamp is differenent from the existing row timestamp then it determines as stale data and it will through the error message.

Please correct me if I'm wrong and also provide some example too.

Thanks in advance.

Prakhyat madgunaki

Joined: Aug 07, 2007
Posts: 1
Below is a simple code, which will depict how optimistic locking/(concurrency control) will be done by hibernate.

// foo is an instance loaded by a previous Session
session = factory.openSession();
int oldVersion = foo.getVersion();
session.load( foo, foo.getKey() );

if ( oldVersion!=foo.getVersion )
throw new StaleObjectStateException();

I agree. Here's the link: http://aspose.com/file-tools
subject: Optimistic concurrency in hibernate using version/timestamp.
Similar Threads
Caching of Database Access Objects's possible?
Original Data Verification before Update
Hibernate + locking
Hibernate Updating a Object
equivalent of on_update current_timestamp in MSSQL.