I have this code:
run big query: Select all unprocessed objects from table A
for each result
create or update an output object in table B
update input object: Set it to "processed"
I'd like to have a transaction over the loop body, that is after one row of input is processed, the updated objects should be committed, so when the program aborts, it won't process all rows again but start with the faulty row.
I'm using Spring 2.5, Hibernate 3.4 and JPA (i.e. I have an EntityManager
).
How do I do that? I tried to call em.getTransaction().commit()
in the loop but Spring won't allow that.