Results 1 to 6 of 6

Thread: Listen to commit errors?

  1. #1
    Join Date
    May 2011
    Posts
    18

    Default Listen to commit errors?

    Hello,

    Is there any listener that i can register to have access to the exception (preferably items that were part of the transaction too) while committing the transaction?

    ItemWriterListener and ChunkListener error methods are called before the transaction is commited, so how can i report/log errors while committing?

  2. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    you can do something before and after commit, but not *while* committing. Spring Batch usually tries to call the listeners as close to the commit as possible, so such callbacks (before the commit) should be enough most of the time. Moreover, an error triggers a rollback (so no commit). What is your scenario exactly?

  3. #3
    Join Date
    May 2011
    Posts
    18

    Default

    I have my job configured to use a reader/processor/writer. Currently i have a commit size of 50 and i dont have any retry or non-rollback exceptions configured. Eventually i will set up retry to 2 probably but non-rollback exceptions will remain empty.

    As for listeners i have jobListener, stepexecutionlistener, itemreadlistener, itemprocesslistener, itemwritelistener and skiplistener configured.

    I am using hibernate.

    What i want to achieve is to be able to log the exception when the application fails to commit the transaction, because currently if that happens none of my listeners works, they are all executed before the commit and since im filtering out all springbatch logs when this happens my job just stops executing without showing or printing anything, which is another concern, i think it should be able to at least keep processing the rest of the items (even if the current chunk failed).

    I can post any code/config you need, just let me know.

    Thanks in advance

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    your listeners log something in the database and they get rollback with the whole chunk, right? If so, use PROPAGATION_REQUIRES_NEW as the propagation level in these listeners. Their work won't be rolled back then.

    If you want to keep on processing items on an error, you should configure skippable exceptions.

  5. #5
    Join Date
    May 2011
    Posts
    18

    Default

    Thanks for the quick answer.

    Currently the listeners only write somethign to a log file, but yea eventually they will write to a DB log/audit table.

    The problem with that is if I log that X records were written to the DB and then the transaction rolls back i have incorrect log/audit information because in reality nothing was written.

  6. #6
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    ok, so your problem will disappear as soon as you use the DB to log read/processed/written items. If you want to stick to a log file, you'll need to flush your logs after the commit, for example after the chunk completion (a chunk listener would be appropriate in this case).

Posting Permissions

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