Announcement Announcement Module
Collapse
No announcement yet.
transaction management in a loop Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • transaction management in a loop

    I have a Dao with basic methods lets say "insertIntoTable1(id, value)" and "insertIntoTable2(id, value)"
    and I have a Service with a basic method lets say "serviceForTable1AndTable2(id,value)"; this service is transactional, and it works fine for one call.

    But I want to call "serviceForTable1AndTable2" in a loop, and make it as one transaction how can I do that.
    I am using annotations for transaction management.
    Thanks in advance

  • #2
    Originally posted by aric View Post
    I have a Dao with basic methods lets say "insertIntoTable1(id, value)" and "insertIntoTable2(id, value)"
    and I have a Service with a basic method lets say "serviceForTable1AndTable2(id,value)"; this service is transactional, and it works fine for one call.

    But I want to call "serviceForTable1AndTable2" in a loop, and make it as one transaction how can I do that.
    I am using annotations for transaction management.
    Thanks in advance
    The main point here is to assure that the following is done:
    1. serviceForTable1AndTable2() uses propagation that allows to participate at existing transaction (e.g. Propagation.REQUIRED);
    2. make multiple serviceForTable1AndTable2() within existing transaction context;

    I.e. you can introduce a dedicated method at the Service like
    Code:
    @Transactional
    public void processAllRecords(Collection<Account> accounts) {
        for (Account account : accounts) {
            insertIntoTable1(account.getId(), account.getBalance());
            insertIntoTable2(account.getId(), account.getNotes());
        }
    }

    Comment

    Working...
    X