Relative Content

Tag Archive for springspring-boottransactionsspring-batch

How to persist h2 changes made inside Spring Batch ItemReader

My goal is that while I am processing my files, to also add them in a persistent H2 instance with their current status: “NEW” during reading, “PROCESSING” in the ItemProcessor, and “COMPLETED” in the ItemWriter. When I initialize the rows inside the ItemReader, I can query and verify their addition using a print statement in Java, by finding them inside the repository using their names. However, in the ItemProcessor step, when I attempt to do the same, I get an error indicating that there is no such object in the database. I understand this issue is related to the way transactions are handled in Spring Batch. Shouldn’t it flush the session after the write step, rather than between steps?