spring-batch
spring-batch copied to clipboard
Improve the documentation regarding transaction management [BATCH-2171]
Mauro Molinari opened BATCH-2171 and commented
I'm new to Spring Batch and my starting point to learn was the reference documentation. However, after reading it, looking at the examples and reading other books about the subject, I was still with some big questions in my head. I found the replies on a few sources, like:
- http://forum.spring.io/forum/spring-projects/batch/74926-spring-batch-and-transactions
- https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/
- https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-2-restart-cursor-based-reading-and-listeners/
- https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-3-skip-and-retry/
What I'm referring about:
- the relationship between the Spring Batch metadata and the business logic data regarding transaction management: should they stay in the same transactional resource or not?
- must the transaction manager passed to the
JobRepositorybe the same as the one passed to the job steps? Please also note that theJdbcCursorItemReaderrepresent an exceptional case - what's the answer to the previous questions when you're in a JEE container and/or you are using a JTA-XA infrastructure?
- how can the examples pass a
HibernateTransactionManagerorJpaTransactionManagerso easily to theJobRespotiory, even if Spring Batch itself does not use Hibernate/JPA? - how exactly are transactions handled for the skip and retry cases? What happens to the chuck processing flow when a skippable/retryable exception is thrown? And how things go instead when this exception is also in
no-rollback-exception-classes?
I think the developer should know exactly how things work regarding transactions when he/she has to setup a Spring Batch environment and/or to configure jobs appropriately. I personally got almost all my replies by reading the above sources, but I suggest to improve the Spring Batch documentation to cover these topics too.
2 votes, 3 watchers
In order to answer the questions above, the following should be done:
- [ ] Update the Javadoc of all methods in the
JobRepositoryinterface with the expected transactional behaviour (ie document at the contract level what is implicitly configured in the proxy created by the factory bean). - [ ] Update the FAQs section (see #3878) with key aspects about transaction management (questions above and more if needed)
- [ ] Update the reference documentation where appropriate (namely the JobRepository configuration and Step configuration sections)
- [ ] Update the appendix about transactions
References:
- https://softwareengineering.stackexchange.com/questions/280747/what-is-the-usefulness-of-transactions-in-a-batch-especially-a-spring-batch
- https://stackoverflow.com/questions/29303155/how-does-spring-batch-transaction-management-work
- https://stackoverflow.com/questions/30458437/how-does-spring-batch-manage-transactions-with-possibly-multiple-datasources
- https://stackoverflow.com/questions/64731298/spring-batch-transaction-management-multi-threaded-step
- https://stackoverflow.com/questions/19031190/transaction-management-in-spring-batch
- https://stackoverflow.com/questions/17947970/transaction-management-with-spring-batch
- https://stackoverflow.com/questions/29761606/spring-batch-transaction-manager-for-two-databases
- https://stackoverflow.com/questions/46237823/how-to-manage-shorter-transaction-inside-spring-batch-chunk/50717491
- https://stackoverflow.com/questions/48072061/in-spring-batch-is-a-job-with-more-than-one-step-considered-as-a-transaction
- https://stackoverflow.com/questions/63039305/spring-batch-do-i-need-a-transactional-annotation
- https://stackoverflow.com/questions/64957794/why-spring-batch-reader-and-writer-use-different-transactions