Spring commit and rollback processing

My question is about Spring package and transactions.

Let's say for one of my steps I chose a fixed interval of 50 .

Also suppose that I have 1000 entries in all and among these entries that will lead to an itemWriter error, which will lead to the rollback of the entire fragment (50 entries in my example).

What are stategies to ensure that 49 valid records are written to the database after the job is completed (and ignored the problem piece)?

+6
source share
1 answer

After some research, I came up with the following:

If the element writer cannot commit a piece (there are 50 elements here), which will result in a rollback, Spring Batch will restart each element of the problem block individually with one commit / transaction for each element.

Consequently, all 49 elements will be present in the database, except for one element due to which Spring Batch rolls back a piece.

+12
source

Source: https://habr.com/ru/post/920200/


All Articles