• 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

Hibernate + locking

 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can Hibernate ensure certain level of optimistic or other sort of locking on a entity(i.e entry in a table)??

Or is it that you need to resort to your own ways for this locking??
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate has built-in support for optimistic locking.
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Loren Rosen:
Hibernate has built-in support for optimistic locking.



Can u elaborate and if the object(or internal data) is being locked does hibernate generate a availability exception(status) or something of that sort???
 
Loren Rosen
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The usual way to do this is to have a version property on the object, a <version> tag in the mapping file, and a version column in the table in the database. This is incremented very time the object is updated, and hibernate can check that the version numbers match when you do an update. If they don't it will throw a StaleObjectStateException.

You can also have it do the same thing with a timestamp column.
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Loren Rosen:
The usual way to do this is to have a version property on the object, a <version> tag in the mapping file, and a version column in the table in the database. This is incremented very time the object is updated, and hibernate can check that the version numbers match when you do an update. If they don't it will throw a StaleObjectStateException.

You can also have it do the same thing with a timestamp column.



So, we can define optimistic locking on a class level, during updates??
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kishore Dandu:
So, we can define optimistic locking on a class level, during updates??

Yes, each class can be set up differently if you like. Optimistic locking is also enforced during delete, and clearly it makes no sense for insert.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic