Spring Batch 6.0.4 - SkipListener and transactions regression ? #5436
-
|
Hi, Not too sure about this one. According to https://docs.spring.io/spring-batch/reference/step/chunk-oriented-processing/intercepting-execution.html#skipListenersAndTransactions :
Since fix 5361 in 6.0.4, a rollback has been added right after skipListener's call : this.compositeSkipListener.onSkipInWrite(item, exception);
contribution.incrementWriteSkipCount();
contribution.getStepExecution().incrementRollbackCount();
status.setRollbackOnly(); // <------ added in 6.0.4Thus, updates made in a skipListener (eg. insert in an error log table) are also rollbacked. In 6.0.3, it used to work out of the box. In 6.0.4, one can mitigate this by forcing a separate transaction with What is the expected behaviour ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Here's a demo project : Let's wait for @fmbenhassine answer before creating an issue. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for raising this! This is a documentation issue. The contract of This is no different with the |
Beta Was this translation helpful? Give feedback.
Thank you for raising this! This is a documentation issue. The contract of
SkipListeneris incomplete and that section of the reference doc is misleading. Here is why: other listeners like ItemWriteListener#onWriteError and ChunkListener#onChunkError, explicitly mention that those methods are executed as part of the transaction driven by the step, which is about to be rolled back. As a result, any transactional operation that is called there should use a separate transaction. There is also a specific example for that use case in Logging Item Processing and Failures, with a similar important note about transactions at the bottom of the section: