alistair wrote:
1) One should not add the version column to the equals/hashCode method because equals is used only for logical equality during code execution.
http://www.hibernate.org/109.htmlYou are right, don't add version to the equals/hashCode. Authours of HIA (chapter 4.1.6) , argue to use "business key equality", that is implement equals/hashCode using only business fields that form business key/natural key (unique combination of business fields), and don't use any synthetic identifiers.
alistair wrote:
2) Whereas the version column is used by Hibernate or application developer to do a "dirty check" between the in-memory instance and its persisted instance.
Version is checked in the SQL UPDATE:
Code:
update User set name='new name' version=3 where userId=123 and version=2
if JDBC execute statement returned zero, you will get StaleObjectStateException. As you see performance do not suffer when you use versioned classes.
Delete should be handled similar. (where userId=123 and version=2)
[quote="alistair"]Another quesiton: in the event of the version number difference, what will Hibernate do when I update a persistent object ?[/code]
you will get StaleObjectStateException
--
Leonid