Im using SpringBatch 2.1.7 release core and Infrastructure jars to read a CSV file and save it to DB.
Integrated my code with Spring quartz scheduler to run for every minute, The Batch is working fine with reading and writing but its failing with the error "org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=1 with wrong version (2), where current version is 1"
due to Tx conflicts. Please suggest how can i resolve this issue.
As pointed out by MattC, I had this error when my
ItemProcessor
was bugged. For some reason, during my processor activities, it was closing the datasource connection withjobrepository
, so my exception was:At the end of the stacktrace, I was able to find:
In order to identify the problem, first I isolate the phase. I constructed a NoOpProcessor and a NoOpItemWriter. Adjusted the tasklet and it worked well. So my problem wasn't into the reader.
Then I rolledback to my "full" ItemWriter implementation, and again, it worked well. So my problem wasn't with the writer to. When I enabled my "full" processor, the error occurred again. So, the error was in it, and I started debugging.
So, unfortunately, my answer is: debug...
I had this same exception.
In my case, it was caused by a failure the process step, which was being swallowed. Spring Batch activated the writer, even though the processor had failed. Look through your logs to make sure that your process step is completing and returning something.