我已将Hibernate升级到5.2.3
,然后通过春季批处理作业获得了org.springframework.dao.OptimisticLockingFailureException
。
Spring的工作是从文件和过程中读取数据,这将创建流程图之类的东西,相关关系将存储在db中。
升级之前,一切正常。是什么原因呢?
Spring Batch version: 3.0.10.RELEASE
当我遇到运行时异常(组件已经存在)然后休眠回滚事务时发生了这种情况,但是春季批处理作业应该继续,但是它抛出错误以下。
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
答案 0 :(得分:0)
我们必须设置此属性才能解决此问题
hibernate.allow_update_outside_transaction=true
有关更多详细信息: https://github.com/hibernate/hibernate-orm/blob/5.2/migration-guide.adoc#misc
请参阅下面的链接以查看发行版中的更改 https://github.com/hibernate/hibernate-orm/blob/master/changelog.txt