Announcement Announcement Module
Collapse
No announcement yet.
Retry after recover Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retry after recover

    Hi all,
    I'm using spring-batch 1.0.0.FINAL.
    My scenario is as follows:
    I read files and inserts their contents into database tables.
    I have a case when I may get a foreign key constraint exception that says me that a foreign key reference in the parent table is absent. In the recovering listener I may insert the absent record that caused the exception. But now I want to retry the insert. While debugging I saw that retries happen before recovering. But I need it to be vise versa.
    I tried to perform the necessary insert in my implementation of RetryListener.onError(), but got a lock timeout in MySQL table.
    I insert file data via iBatis, but add the necessary record in the parent table via Hibernate. For Hibernate save operation I use @Transactional(propagation=Propagation.REQUIRES_NE W) as I want the record to be saved in a new transaction (and be accessible for other jobs that may need this record). But the current transaction causes the lock in database (MySQL InnoDb is used for all the tables).
    So I have 2 questions.
    1. How may I eliminate the lock?
    2. How can I run retries after recovering so that newly created Hibernate transaction will be closed before new retries?

    Alex.

  • #2
    I'm not sure how Spring Batch can help with the lock. It sounds like some other piece of code is causing that record to be locked. You were right the first time to use a RetryListener to try and change that. Recover is really meant to be called after an item has 'failed to retry' meaning that we've retried it the normal number of times and can't get it to work, so we're skipping and 'recovering'.

    It sounds like you're using hibernate, is it possible that something hibernate is doing is causing that record to be locked?

    Comment

    Working...
    X