Database versioning + entity listener causes stale object exception when

Description

Test case available here:
https://github.com/apixandru/case-study/tree/master/hibernate-versioning

(I tried creating a standard hibernate test case but i don't know how to create this trigger in h2 and how to create the schema manually from the test.)

I'm using versioning as time stamps generated by the database as described here https://docs.jboss.org/hibernate/orm/5.0/devguide/en-US/html/ch05.html#d5e1309

It all works well until I attach a EntityListener to the entity. After that, it identifies the entity as being modified, which triggers an update on the version.

I think that the (if necessary) in the code below should also include not generating the next version if the database generates the timestamp

The EntityUpdateAction does a check but it looks like it is a bit too late at that point since previousVersion was the correct version and the 'persister.getVersion( instance )' call actually gets the wrong version

Environment

None

Assignee

Unassigned

Reporter

Alexandru-Constantin Bledea

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure