I'm trying to select data from database, update each object and then update the database in an itemwriter.
I tried to flush DAO after each update but it's change nothing.
The configuration is very basic with a reader, a writer and a commit-interval of 100.
The reader is working as expected:
@Override
public Order read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
if(iterator == null) {
List<Order> all = findOrders();
iterator = all.listIterator();
}
if (iterator.hasNext()) {
return iterator.next();
} else {
return null;
}
}
The writer is very basic too:
public void write(List<? extends Order> items) throws Exception {
@SuppressWarnings("unchecked")
List<Order> listOrder = (List<Order>) items;
try {
for(Order o : listOrder) {
etatCommandeServiceImpl.updateEtatCommande(o);
}
}catch(Exception e) {
if (log.isErrorEnabled()) {
log.error("ERROR {}", e);
}
throw e;
}
}
The issue is that the first 100 records are commited but not the rest. Spring batch table shows that it reads all records and commits multiple times but when I check in the database it's just commit once.
The version of Spring-batch is 2.2.6.
UPDATE
I think this problem is due to the transaction with database, because now it doesn't commit at all to the database. But I can't figure it out for the moment.