im using JPA2 with Hibernate 3.6.x
I have made a simple testing on the @Version.
Let\'s say we have 2 entities,
It looks like a bug in Hibernate.
JPA Specification says:
All non-relationship fields and properties and all relationships owned by the entity are included in version checks
However, Hibernate also increments version after change of non-owned relationship properties (whereas, for example, EclipseLink doesn't do it). This behaviour can be disabled by setting @OptimisticLock(exclude = true)
on the property.
Note that it's only applicable to changes of relationship property itself, not to changes in the state of referenced objects, so that version of parent wouldn't be changes due to changes in collection of grandchildren.