I am working on a Spring Batch application that will Read unprocessed data from Table A, process the Data, Insert the processed Data to Table B, and then Update the row in Table A to PROCESSED. However, while Inserting the data into Table B works fine, I keep getting a DeadlockLoserDataAccessException every time I try to Updated Table A. I believe this is due to the Curser from the JDBCCursorItemReader that was used to read Table A is getting in the way of Updating the Table. How would I go about fixing this?
I use a JDBCCursorItemReader and CompositeItemWriter in the Spring Batch. The chunk size is 1.
This should not cause a problem if both the read, insert and update are within the same transaction (which is the case when you use a chunk-oriented step).
Here is a quick (self-contained) example with the same config as you mentioned:
It reads persons from a
Person
table (TableA in your case), uppercase their name and writes the result in aPeople
table (TableB in your case). Then it updates theprocessed
flag on thePerson
table.If you run the sample, you should see:
without any dead lock exception.
Hope this helps.