Jun 19th, 2009, 09:31 AM
The ItemWriter's write method does not receive Data Integrity Violation exceptions, instead they are caught by the StepTasklet after the write method is safely returned.
Looks like all the update statements in the write method are batched and are executed after the write method returns.
My requirement is to continue with successful updates and ignore failures.
Jun 20th, 2009, 11:06 AM
Which implementation of ItemWriter are you talking about? What version of Spring Batch?
In any case, ignoring DataAccessException should just be a matter of setting up a skipLimit and including that exception in the list of skippables.
Jun 21st, 2009, 08:13 AM
Thank you very much for you response and sorry for not including the proper details.
It is custom writer which implements ItemWriter. It inserts the list of items into the database using a hibernate template (i.e. indirectly through a DAO).
My intension is to insert all the items into the database and if any item violates the unique primary key constraint, I just want to catch and log the error continuing with the next item in the list.
Note: I don’t want to skip the whole step on a primary key violation exception and want to have commit interval > 1.
For now I achieved it making the commit interval 1, Configuring a shippable exception and configuring an ItemWriterListener’s onWriteError method to log the error message. My concern here is I am forced to put commit interval 1 where I want it to be > 1.
Jun 21st, 2009, 08:23 AM
What you are describing is the default skip behavior is spring batch. As long as you configure the exception to be skippable, no matter what the commit interval is, it will only skip the items that cause the exceptions. All non-exception-throwing items will be committed.
Tags for this Thread