org.springframework.dao.OptimisticLockingFailureException with hibernate upgrade

ぐ巨炮叔叔 提交于 2020-06-17 11:32:46

问题


I have upgraded Hibernate to 5.2.3 then I am getting org.springframework.dao.OptimisticLockingFailureException with spring batch job.

Spring job is to read data from file and process which will create flow chart kind of thing and related relations will be stored in db.

Before upgrade everything was working fine. What is the reason for this?

Spring Batch version: 3.0.10.RELEASE

It is happening when I got runtime exception(component already exists) then hibernate rollbacks the transaction but spring batch job should continue but it is throwing below error.

org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=0 with wrong version (1), where current version is 2
    at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:257) ~[spring-batch-core-3.0.10.RELEASE.jar:3.0.10.RELEASE]
    at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:191) ~[spring-batch-core-3.0.10.RELEASE.jar:3.0.10.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_221]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_221]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_221]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at com.sun.proxy.$Proxy207.update(Unknown Source) ~[?:?]
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:456) [spring-batch-core-3.0.10.RELEASE.jar:3.0.10.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) [spring-batch-core-3.0.10.RELEASE.jar:3.0.10.RELEASE]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) [spring-tx-4.3.23.RELEASE.jar:4.3.23.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272) [spring-batch-core-3.0.10.RELEASE.jar:3.0.10.RELEASE]
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) [spring-batch-core-3.0.10.RELEASE.jar:3.0.10.RELEASE]
    at org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:262) [spring-batch-infrastructure-3.0.10.RELEASE.jar:3.0.10.RELEASE]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_221]
14:52:18,095 ERROR [TaskletStep] JobRepository failure forcing rollback

回答1:


We have to set this property to resolve this issue

hibernate.allow_update_outside_transaction=true

For more details: https://github.com/hibernate/hibernate-orm/blob/5.2/migration-guide.adoc#misc

Refer below link to view what changed over the releases https://github.com/hibernate/hibernate-orm/blob/master/changelog.txt



来源:https://stackoverflow.com/questions/61405357/org-springframework-dao-optimisticlockingfailureexception-with-hibernate-upgrade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!