Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!