I have a java project that runs on a webserver. I always hit this exception.
I read some documentation, and found that pessimistic locking (or optimistic, but I read
I had the this problem on my project.
After I implemented optimistic locking, I got the same exception.
My mistake was that I did not remove the setter of the field that became the @Version
. As the setter was being called in java space, the value of the field did not match the one generated by the DB anymore. So basically the version fields did not match anymore. At that point any modification on the entity resulted in:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
I am using H2 in memory DB and Hibernate.