[Solved] Hibernate Error: Row was updated or deleted by another transaction

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

org.hibernate.StaleObjectStateException:Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

Error reporting reason:

1. The current version is not consistent with the db database version, the data is modified when the value of the form object in the version and the value of the corresponding record in the database version is not consistent, which makes the update method in the call, the version is not consistent with the reverse error.
2. Two or more sessions have modified the same record

Encountering such an exception indicates that the object of the operation uses an optimistic lock or the defined POJO defines the version field

Solution:

1. When submitting the form data, submit the version as well
2. First query the value of the version of the corresponding record in the database and assign it to the entity object to be modified, and then execute the update operation (after modifying the database data, the value of its version will change, so at this time the update operation needs to obtain the latest version value, assign it to the operation object, and then execute the update operation)

Read More: