Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting ObjectOptimisticLockingFailureException without version annotation or OptimisticLocking strategy

I am getting optimistic locking exception (mentioned below) but strange thing is we haven't specified any of our entities with @version annotation or OptimisticLocking, so just wondering what can cause this exception? We are using JPA, hibernate, spring data & spring. Database is postgresql.

System exception occurred while processing request, ERROR_CODE: a18d5739 org.springframework.orm.ObjectOptimisticLockingFailureException: 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
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:301)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
like image 750
suraj bahl Avatar asked Oct 24 '25 04:10

suraj bahl


1 Answers

This is not about Optimistic lock. This exception is throwing while deleting/updating a record by Id that does not exists at all. So check that record you are updating/Deleting actually exists in DB.

However, to get a better handle as to what causes the problem you can:

1) Set show_sql as true 2) Set the log levels for Spring and Hibernate to DEBUG

This will help you to understand the issue and fix it.

like image 106
jack1590 Avatar answered Oct 26 '25 18:10

jack1590