休眠升级时出现org.springframework.dao.OptimisticLockingFailureException [英] org.springframework.dao.OptimisticLockingFailureException with hibernate upgrade

查看:707
本文介绍了休眠升级时出现org.springframework.dao.OptimisticLockingFailureException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Hibernate升级到5.2.3,然后通过Spring Batch作业获得了org.springframework.dao.OptimisticLockingFailureException.

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

Spring的工作是从文件和过程中读取数据,这将创建流程图之类的东西,相关的关系将存储在db中.

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

当我遇到运行时异常(组件已经存在)然后休眠回滚事务时发生这种情况,但是spring batch job应该继续,但是它抛出错误以下.

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

推荐答案

我们必须设置此属性来解决此问题

We have to set this property to resolve this issue

hibernate.allow_update_outside_transaction=true

有关更多详细信息: https://github.com/hibernate/hibernate- orm/blob/5.2/migration-guide.adoc#misc

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

请参阅下面的链接以查看发行版中的更改 https://github.com/hibernate/hibernate-orm/blob/master/changelog.txt

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

这篇关于休眠升级时出现org.springframework.dao.OptimisticLockingFailureException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆