OptimisticLockingFailureException updating step execution after commit failure in Spring Batch

user3815986 picture user3815986 · Sep 11, 2014 · Viewed 7.6k times · Source

I am performing some integration testing for my application in which I am trying to force an exception whenever there is an update/insert happening in the database. Whenever any exception thrown due to this the Spring batch step hangs with the below exception

Caused by: org.springframework.dao.OptimisticLockingFailureException: Attempt to
 update step execution id=10657 with wrong version (1), where current version is
 2
        at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.up
dateStepExecution(JdbcStepExecutionDao.java:185)
        at org.springframework.batch.core.repository.support.SimpleJobRepository
.update(SimpleJobRepository.java:171)
        at sun.reflect.GeneratedMethodAccessor227.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:317)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.
proceedWithInvocation(TransactionInterceptor.java:96)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.
invokeWithinTransaction(TransactionAspectSupport.java:260)
        at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:94)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:204)
        at $Proxy74.update(Unknown Source)
        at org.springframework.batch.core.job.flow.JobFlowExecutor.abandonStepEx
ecution(JobFlowExecutor.java:76)
        at org.springframework.batch.core.job.flow.support.state.StepState.handl
e(StepState.java:59)
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(Sim
pleFlow.java:144)

Tried searching in spring Forum and it seems to be a bug as per https://jira.spring.io/browse/BATCH-1767.

Has anyone came across this issue and is there any solution for this? I am using JTA transaction manager ,eclipselink and Spring batch version 2.1.7 in my application.

Answer