To learn how to use optimistic locking, I tried to create a very simple example program.
I have a simple Person entity, with a primary key, two properties firstName and name, and a version field (of type int).
Creating a Person and saving it gives it a version of 0. Now, if I just do
Code:
t=session.beginTransaction();
session.update(person);
t.commit();
the version field in my Person is incremented, even if the Person instance was not changed (not dirty). My expectation was that the version fields was only incremented when a "dirty" person was updated.
Is incrementing the version number on each update the expected behaviour, or did I miss something (maybe some configuration issue)?