Announcement Announcement Module
Collapse
No announcement yet.
Help with no-rollback-exception-classes configuring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with no-rollback-exception-classes configuring

    Hi all,
    my use case is a simple batch repeat.
    My job configuration:
    <batch:job id="job" job-repository="jobRepository">
    <batch:step id="step1" next="step2">
    <batch:tasklet ref="beforeCustomerProcessingTasklet"/>
    </batch:step>
    <batch:step id="step2">
    <batch:tasklet>
    <batch:chunk reader="customerReader"
    processor="customerProcessor" writer="customerWriter"
    commit-interval="${job.commit.interval}"
    >
    </batch:chunk>
    </batch:tasklet>
    </batch:step>
    </batch:job>

    We need when org.springframework.dao.DataAccessException occurs:
    1) Do not rollback(checkUpdateCounts function log sql failures. )

    public class CustomerWriter implements ItemWriter<Customer>
    ...
    public void write(List<? extends Customer> items) throws Exception {
    ...
    if (sqlList != null && sqlList.size() > 0) {
    try{
    int[] updateCounts = getJdbcTemplate().batchUpdate(
    (String[]) sqlList.toArray(new String[sqlList.size()]));
    checkUpdateCounts(updateCounts,(String[]) sqlList.toArray(new String[sqlList.size()]));
    logger.debug(format("{0} queries has been processed",
    String.valueOf(sqlList.size())));
    }
    catch(DataAccessException e){
    BatchUpdateException bue = ((BatchUpdateException)e.getCause());
    int[] updateCounts = bue.getUpdateCounts();
    checkUpdateCounts(updateCounts,(String[]) sqlList.toArray(new String[sqlList.size()]));
    throw e;
    }
    }
    ...
    2) Do not stop job execution(some other process wil process fault queries)

    So thats our new job config:

    <batch:job id="job" job-repository="jobRepository">
    <batch:step id="step1" next="step2">
    <batch:tasklet ref="beforeCustomerProcessingTasklet" />
    </batch:step>
    <batch:step id="step2">
    <batch:tasklet>
    <batch:chunk reader="customerReader"
    processor="customerProcessor" writer="customerWriter"
    commit-interval="${job.commit.interval}"
    >
    <batch:skippable-exception-classes>org.springframework.dao.DataAccessExceptio n
    </batch:skippable-exception-classes>
    </batch:chunk>
    <batch:no-rollback-exception-classes>
    org.springframework.dao.DataAccessException
    </batch:no-rollback-exception-classes>
    </batch:tasklet>
    </batch:step>
    </batch:job>

    And I would expect to have the desired behaviour but... it does not work. The process keeps retrying and do not finishes. If I remove the skip configuration, then the process finishes but it does rollback. What is it wrong?
    Thanks.

  • #2
    There are some restrictions on no-rollback, and in particular we always rollback after an exception in an ItemWriter. I don't think it really makes sense not to roll back even in your use case unless I am missing something - if you really think you have dealt with the failure in your catch clause, why would you re-throw? If you get into an infinite loop that's a bug, but you should expect weird behaviour if a skippable exception is also marked as no-rollback.

    Comment

    Working...
    X