Results 1 to 9 of 9

Thread: Whole-Batch transaction

  1. #1
    Join Date
    Nov 2008
    Posts
    14

    Default Whole-Batch transaction

    Hi,

    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,
    Matthias.

  2. #2

    Default

    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. #3

    Default

    Hi

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

    Default

    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. #5
    Join Date
    Nov 2008
    Posts
    14

    Default

    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.

  6. #6
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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. #7
    Join Date
    Nov 2008
    Posts
    14

    Default

    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. #8
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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. #9
    Join Date
    Nov 2008
    Posts
    14

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •