|
See the attached test case, test is: testUpdateParentAfterRemoval Also see description on: https://forum.hibernate.org/viewtopic.php?f=1&t=1035627
In short: in case a perform an EM.lock() on an entity and afterwards an EM.remove(), this will always result in a OptimisticLockException (newer version [null] of entity [[...]] found in database.
The cause is that the lock action is not canceled when the EM.remove() is performed. The action is performed at the end of the transaction. It queries for the latest version of the affected entity (which has been removed and thus is null). Null != the actual version --> OptimisticLockException.
Project can be switched to use Eclipselink, which performs the expected behaviour correctly.
|