3493

org.springframework.dao.OptimisticLockingFailureException with hibernate upgrade

<h3>Question</h3>

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
<h3>Answer1:</h3>

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

Recommend

  • random font for website text?
  • Maven Resources Plugin: Build won't fail if directory doesn't exists
  • How to process future stream to create an instance of class with list property
  • how do I array from a GET request function in viewdidload function in swift
  • Bounding csv data to topojson path - cloropleth
  • Why does IntStream.range(0, 100000).parallel.foreach take longer then normal for loop
  • Getting a photo of a place from Google Places Api
  • Box shadow not working in microsoft edge
  • Problems installing Common Lisp Sketch into Windows 10
  • How to concatenate data.frame inside lists by using names?
  • Parsing a complicated array with GetJSON Jquery
  • Call a specific instance of a service in Azure Service Fabric
  • Octopress --> Heroku error env: bundle: no such file or directory
  • Mask Image to Video Frame similar as MV Master
  • Pyinstaller GLIBC_2.15 not found
  • Specify the _id field using Bulk.IndexMany in ElasticSearch
  • Identifying dates in strings using NLTK
  • connect.cookieParser and connect.session
  • Generate a runnable jar and include libraries in it with Maven
  • Is there a .NET method equivalent to NETWORKDAYS in Excel?
  • create circular Auto Horizontal Scroll View?
  • git clone, upload-pack out of memory
  • Splitting ReportLab table across PDF page (side by side)?
  • Julia 1.0 UndefVarError - Scope of Variable
  • How to merge objects within array based on attribute
  • Zoho API: Get the user that is making the request
  • Problems to understand DXGI DirectX 11 Desktop Duplication to get a Buffer or Array
  • How to make 100% div height between header and footer?
  • C++ STL stack pop operation giving segmentation fault
  • Calculate time from document
  • 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs
  • Amazon Elastick BeanStalk error: Failed to create the AWS Elastic Beanstalk application version
  • how to get the location(lat/lng) on google maps v3 from the location(x,y)
  • Terminal run dalvikvm with am.jar
  • VSTS work items list through REST API
  • Functions by reference or by variable, which to use when?
  • Can someone explain this Java code (formatting the output using System.out.format) to me?
  • Sql - ON DUPLICATE KEY UPDATE
  • Angular FormGroup won't update it's value immediately after patchValue or setValue
  • ARKit code issue {unknown error -1=ffffffffffffffff error: Task failed with exit 1}