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

前端 未结 17 1894
别跟我提以往
别跟我提以往 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 16:55

    I also ran into this error when attempting to update an existing row after creating a new one, and spent ages scratching my head, digging through transaction and version logic, until I realised that I had used the wrong type for one of my primary key columns.

    I used LocalDate when I should have been using LocalDateTime – I think this was causing hibernate to not be able to distinguish entities, leading to this error.

    After changing the key to be a LocalDateTime, the error went away. Also, updating individual rows began to work as well – previously it would fail to find a row for updating, and testing this separate issue was actually what led me to my conclusions regarding the primary key mapping.

提交回复
热议问题