0

Regarding the post How does Spring Batch CompositeItemWriter manage transaction for delegate writers? , for composite item writer transaction management, shouldn't we wrap the data source in a transaction manager like below ? Without the below bean definition the transaction management is not working with Oracle and Hikari CP. Not sure how the provided example in the post is working..please clarify

@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
            return new DataSourceTransactionManager(dataSource);
}
LBPS
  • 83
  • 9

1 Answers1

0

There is no need to add that bean, the example provides a DataSource and uses @EnableBatchProcessing, so Spring Batch will configure a DataSourceTransactionManager by default. This is explained in the documentation of @EnableBatchProcessing.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • I am setting the spring batch datasource as null by extending DefaultBatchConfigurer because I dont need that feature.. ``` @Override public void setDataSource(final DataSource dataSource) { // initialize with NULL to do in-memory job initialization super.setDataSource(null); } ``` Could that be the reason it is not working for my application datasource without the Datasource transaction manager definition? it only works when I I add the Datasource transaction manager bean explicitly – LBPS Oct 26 '20 at 21:37
  • do you think it is causing the issue ? – LBPS Nov 05 '20 at 00:24
  • No, in this case, you need to define the transaction manager yourself and set it on the step. – Mahmoud Ben Hassine Nov 05 '20 at 08:09