We have many steps inserting/updating data through Hibernate.
When an exception occurs in one of the step, we want to rollback the entire job. We use both item-oriented and tasklet steps.
Is it possible to manage one single transaction per job ?
Spring batch version: 2.0.0 CI SNAPSHOT
Spring version: 2.5.5
Hibernate version: 3
Thank you in advance for your advice,
Spring Batch allows you to set commit interval, so you can easily set it to something like Integer.MAX_INT, but it's up to you to consider how well that's going to work in practise.
I think his issue is the same with mine. If i have a batch job which imports data from text file to db , currently I just set the commitinterval to max integer ( which is actually quite stupid but i dont know other workaround ). Someone advised me to use tasklet but i dont know how to incorporate the flatfilereader and itemwriter from tasklet.
is there better workaround?
I see nothing wrong with just using max integer if you're confident that processing all data in a single transaction is a good idea in your particular usecase.
Thank you for your answers.
The problem is we are using StaxEventItemWriter.
This writer delegates the final write of the xml file to TransactionAwareBufferedWriter, that waits before a commit to flush.
As we set a single transaction around JobLauncher.run(),
TransactionAwareBufferedWriter tried to flush after the end of the job.
The only workaround we found was to import StaxEventItemWriter in the project, to use an OutputStreamBuffer directly.
What's the point of having a transaction at all if you don't synchronize the flush of your writer? You won't be able to use restart, retry or skip features. Is that what you need?
Cleaning the file system in case of error is managed in a separate service.
When an error occurs during the transaction, files are manually deleted.
TransactionAwareBufferedWriter is not appropriate in my case:
- Step 1: hibernate reader + stax writer
- Following TaskletSteps: file operation such as xsd validation, encryption, compression.
The TransactionAwareBufferedWriter writes the file at the end of job, so it is not possible to work on the ouput xml file during the job !
None of those operations seems to be operating on a transactional resource, so if there is an error nothing will rollback anyway. What's wrong with just using the normal stax writer with a moderate sized commitInterval?
The job logs errrors into the database.
Logs have to be written only if the job completely succeeded.
I have others jobs that are transactional too (with a single transaction),
and I want to keep the same transaction handling for all jobs.