Announcement Announcement Module
No announcement yet.
Whole-Batch transaction Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Whole-Batch transaction


    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 ?

    Our configuration:
    Spring batch version: 2.0.0 CI SNAPSHOT
    Spring version: 2.5.5
    Hibernate version: 3

    Thank you in advance for your advice,

  • #2
    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.


    • #3

      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?


      • #4
        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.


        • #5
          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,
          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.


          • #6
            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?


            • #7
              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 !


              • #8
                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?


                • #9
                  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.