• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Optimistic concurrency in hibernate using version/timestamp.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Sharath.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();

foo.setProperty(“bar”);
session.flush();
session.connection().commit();
session.close();
 
reply
    Bookmark Topic Watch Topic
  • New Topic