The most easiest way, I know about is by referencing old values and using them within the update clause. It is like the old lazy locking sheme goes:
Code:
1. Fetch objectA
2. Remember objectA as oldObjectA
3. Do lots of calculation
4. Start transaction
5. Compare current status of objectA in the database and compare it with the old status of objectA
6. write changed status of objectA
7. end transaction
Comparing and setting can be done within the same SQL update clause. It isn't that neat but often enough it is a nice idea for simple workflow situations and legacy tables. (beside the old multi-processor assembler stuff).
@creatxr
Check out this resource to give a nice introduction into locking versioning and stuff: http://developer.apple.com/documenta...Topics.2a.html
I know the solution of versioning --- it seems to add a version field to table. is it correct? how about timestamp?
Check out the hibernate reference manual (or Hibernate in Action if you have) and check out the version and timestamp tag. There is a short but complete discussion about when to use which and why versioning is preferable.
The related Hibernate manual parts can be found at: http://www.hibernate.org/hib_docs/v3...ration-version
Cheers,
Martin (Kersten)