Test case available here:
(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