Skip to content

RepositoryItemWriter does not flush batch #5073

@fmbenhassine

Description

@fmbenhassine

Discussed in #5034

Originally posted by Walnussbaer October 17, 2025
Simple question: why is there even a RepositoryItemWriter based on CrudRepository?

It does not make sense to me, because CrudRepository does not provide the saveAllAndFlush method.

So to me this ItemWriter is not compatible with the rollback logic of Spring Batch. How shall Spring Batch know when to rollback if the flush is happening outside of the actual step? If something goes wrong flushing the data to the database, the writer has already returned, so Spring Batch cannot rollback the transaction and repeat the chunk.

Is this intended behaviour and do I get something wrong?

Any helpful answer is appreciated.

Also, https://docs.spring.io/spring-batch/docs/4.3.8/reference/html/readersAndWriters.html#itemWriter states the following:

After writing out the list, any flushing that may be necessary can be performed before returning from the write method. For example, if writing to a Hibernate DAO, multiple calls to write can be made, one for each item. The writer can then call flush on the hibernate session before returning.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions