I'm having trouble with Spring Batch regarding the configuration of my custom writer which is basically a RepositoryItemWriter
@Bean
@StepScope
public ItemReader<DTO> itemReader() {
[...]Reading from database and mapping into DTO class
return reader;
}
@Bean
@StepScope
public ItemProcessor<DTO, Entity> itemProcessor(mapper) {
return dto-> {
dto.check();
return mapper.toEntity(dto);
};
}
@Bean
@StepScope
public ItemWriter<Entity> itemWriter() {
[...]Save into database from repository
return writer;
}
@Bean
public Step step() {
return stepBuilderFactory.get("step")
.<DTO, Entity>chunk(500)
.reader(itemReader)
.writer(itemWriter)
.build();
}
I am using mapstruct to map DTO to Entity within the processor. Even though it seems to be right, my writer is actually receiving DTO items instead of Entity and thus cannot persist them.
Some complementary but irrelevant information on the structure of the batch. I'm reading from a large file, splitting it into smaller files. Then I'm partitioning my step with a multi resource partitioner, processor is doing a few format controls then the writter just batch insert it into database.
Edit : I guess I could copy/paste the generated source but the MapperImpl is pretty straight forward :
@Override
public Entity toEntity(DTO dto) {
if ( dto == null ) {
return null;
}
Entity entity = new Entity();
[Bunch of controls and mapping]
return entity;
}
That's pretty much it.
Thank you for your help