Manage internal transaction settings from an external transaction using Spring 2.5

I am using Spring 2.5 transaction management, and I have the following setup:

Bean1

@Transactional(noRollbackFor = { Exception.class })
public void execute() {
  try {
    bean2.execute();
  } catch (Exception e) {
    // persist failure in database (so the transaction shouldn't fail)
    // the exception is not re-thrown
  }
}

Bean2

@Transactional
public void execute() {
  // do something which throws a RuntimeException
}

A failure is never saved to the database from Bean1 because the whole transaction is rolled back.

I do not want to add noRollbackFor to Bean2 because it is used in many places that do not have logic for correctly handling runtime exceptions.

Is there a way to avoid rolling back my transaction only when Bean2.execute () is called from Bean1?

Otherwise, I think my best option is to keep my refusal in a new transaction? Anything else I can do?

+4
1

... !

XML, .

, XML: , bean2 . , , .

+1

All Articles