Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

前端 未结 17 1852
别跟我提以往
别跟我提以往 2020-12-02 16:36

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

17条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 17:02

    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.

提交回复
热议问题