Announcement Announcement Module
No announcement yet.
Proper onWriteError exception handling Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Proper onWriteError exception handling

    This is somewhat relates to, but have a different angle to it. Here is goes...

    We have a listener that listens onWriteError, and handles exceptions there. This listener is registered with the step that has an ItemWriter that is wrapped with a "HibernateAwareItemWriter".

    Currently when the "writer writes" to the DB, it flushes right away (HibernateAwareItemWriter flushes hibernateTemplate behind the scenes), so if there is a DB related exception, it is handled properly in onWriteError method (and the item is skipped) right at the moment of processing that very item.

    So, the above describes a "commit interval = 1" scenario, cause every time you process an item "hibernateTemplate" is flushed.

    The question is, if we wanted to use a "commit interval = N" ( where N > 1 ), then this, DB related exception, for an arbitrary item would happen on commit in ItemOrientedStep:
    try {
    which will result in improper exception handling as well as it would fail the job.

    What is a proposed solution to use "commit > 1" with proper onItemProcessing exception handling?

    Thank you

  • #2
    The Hibernate Session needs to be flushed before that. That's what HibernateAwareItemWriter does, in fact - it flushes on the ItemWriter.flush(). The other thing it does is flush more aggressively after a failure, until it locates the failed item (at which point you should get all the normal exception handling). You shouldn't have any problem with commitInterval>1 as a result. Is there a problem, or are you just expecting one?


    • #3
      Hi Dave,

      No, not a problem - just expecting one

      I saw that on ItemOrientedStep, when it commits the transaction, it flushes, and if there is any Exception on flush, AbstractTransactionalResourceItemWriter adds all items in chuck to the HashSet ( failed.addAll(getProcessed()); ) and then ItemOrientedStep rolls back. Then it repeats processing the same chunk, and now it flushes all items in this chunk within the write method - which will result in the proper exception handling onWrite.

      I have not tested it yet myself, just wanted to see that my understanding is correct.

      And if it is, I would add a little more explanation to the "3.8.3. Database ItemWriters" documentation. But it is up to you guys, of course.