I have a JPA entity Person which has a @Version long version field. I do the following:
<<transaction - begin>>
person.getId() --> == NULL
person.setVersion(1);
em.persist(person);
person.getId() --> returns 1 (this one is generated inside the persist call)
person.getVersion(); --> returns 1
<<transaction - end>>
Now if I check the DB, the version = 2, but the bean incorrectly contains 1.
I see the id of the person entity gets reflected correctly in the person instance. However, the version remains the one before calling persist(). Why?
Maybe you are “outside” the specification borders:
(Quote from JPA specification)