Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Stale Data

 
sameer meher
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please give an example regarding how to implement the Stale Date using version/timestamp.
I could find proper example in internet?

Among version/timestamp which one is better and why?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Version or Timestamp? Hibernate doesn't supply a specific timestamp mapping you can use to support optimistic locking. It does allow you to use a field with a timestamp data type for versioning. The hibernate documentation explains how to use the version element. To paraphrase what it says there, it's fairly simple to do: add a version element to your mapping, point it a a suitable attribute of your entity and that's it, Hibernate will do all the nuts and bolts work to implement optimistic locking.

The documentation also explains why using a numeric data type is better than a timestamp; specifically timestamps could very occasionally clash which means you may get lost updates. This is an edge case, becasue in the real world this is very unlikely but not imposible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic