0

I have a conventional spring-batch job where I read from database, process domain objects and write it out to a file.

I need to slightly tweak the functionality during the processor phase so that I can update and commit the domain object to the database and the write it out to a file. I would need the commit to happen instantly as I would require the database ID for the write phase.

When I tried updating the domain object and saving it, I noticed that the entity was getting committed after the write phase.

Is there any way to force the commit to happen instantly during the processor phase and continue as before?

Mahesh
  • 335
  • 1
  • 4
  • 19

1 Answers1

0

I would need the commit to happen instantly as I would require the database ID for the write phase.

i am not sure what id do you need, as you should already have one, when you are trying to update an (existing) entry

if you meant insert, you can work around this issue by using database specific functions to get the id of the inserted but not yet commited object

e.g. for oracle - Obtain id of an insert in the same statement

When I tried updating the domain object and saving it, I noticed that the entity was getting committed after the write phase.

that is desired behaviour, because the write part is the last one within the (chunk)transaction, if it is successful - commit, if not - rollback, imagine a successful commit and a problem with the file, the item in the database would have a wrong state

Community
  • 1
  • 1
Michael Pralow
  • 6,560
  • 2
  • 30
  • 46