Optimistic locking @Version annotation causes spurious update on merge() of detached objects ( but not saveOrUpdate() ) when nothing has changed
Description
A simple Parent -> Child with @OneToMany children.
If have a detached object that has zero changes from the previously saved object and you call session.merge() a spurious update is generated if the Parent has an optimistic locking @Version field. However, no spurious update is generated if :
There is no @Version field
session.saveOrUpdate() is used instead of session.merge()
Here is the std-out to kind illustrate the issue. Note the update statement.
A simple Parent -> Child with @OneToMany children.
If have a detached object that has zero changes from the previously saved object and you call session.merge() a spurious update is generated if the Parent has an optimistic locking @Version field.
However, no spurious update is generated if :
There is no @Version field
session.saveOrUpdate() is used instead of session.merge()
Here is the std-out to kind illustrate the issue. Note the update statement.
Here is Test case