简体   繁体   中英

org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException

When running the getsession.update(data) getting below error;

org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

Please help me resolve the issue.

issue is occuring becouse batch update supposed to update atlest one row, but it did not update any row. becouse your are trying to update row that row is deleted, so batch update is not updating the row and throwing exception.

From documentation:

public class StaleStateException extends HibernateException
Thrown when a version number or timestamp check failed, indicating that the Session contained stale data (when using long transactions with versioning). Also occurs if we try delete or update a row that does not exist .
Note that this exception often indicates that the user failed to specify the correct unsaved-value strategy for a class!

So, check:

  1. Does updating entity exist in a DB?
  2. Are there any modifications of the entity which may make it stale?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM