I have encountered an odd issue with a RepositoryItemWriter, where it does not appear to be persisting entities correctly through my configured Spring Data JPA repository to the
Looks like I fixed it by adding a PlatformTransactionManager. See changes below. Hope this helps someone, as this is one that I've been fighting for a couple of weeks now. What I don't understand is why Spring Boot is able to provide a JtaTransactionManager w/o Bitronix or Atomikos in my pom.xml.
@SuppressWarnings("SpringJavaAutowiringInspection")
@Bean
public Step orderStep(StepBuilderFactory stepBuilderFactory, ItemReader<OrderEncounter> orderEncounterReader, ItemWriter<List<Order>> orderWriter,
ItemProcessor<OrderEncounter, List<Order>> orderProcessor, TaskExecutor taskExecutor, PlatformTransactionManager platformTransactionManager) {
return stepBuilderFactory.get("orderStep")
.<OrderEncounter, List<Order>> chunk(10)
.reader(orderEncounterReader)
.processor(orderProcessor)
.writer(orderWriter)
.taskExecutor(taskExecutor)
.transactionManager(platformTransactionManager)
.build();
}
And the configuration class:
@Configuration
public class JTOpenDataSourceConfiguration {
@Bean(name="distillerDataSource")
@Primary
@ConfigurationProperties(prefix="spring.datasource.distiller")
public DataSource distillerDataSource() {
return DataSourceBuilder.create().build();
}
@Bean
@ConfigurationProperties(prefix="spring.datasource.target")
public DataSource targetDataSource() {
return DataSourceBuilder.create().build();
}
@Bean
public PlatformTransactionManager platformTransactionManager(@Qualifier("targetDataSource") DataSource targetDataSource) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setDataSource(targetDataSource);
return transactionManager;
}