A developer implements a CMT session bean with a method storeBoth which inserts data both a related database and an LDAP server. The relational database supports transactions while the LDAP system does NOT.
Given that both updates should succeed or be rolled back, while is the best solution?
Correct Answer: C
Explanation/Reference:
The method should start a new transaction, so we use the REQUIRED_NEW attribute.
For the LDAP operation we can only detect LDAP exceptions. We cannot check the status of the LDAP operation through SessionContext.getRollBackOnly.
Note:
* CMT - Container-Managed Transactions
* RequiresNew Attribute
If the client is running within a transaction and invokes the enterprise bean's method, the container takes the following steps:
Suspends the client's transaction
Starts a new transaction
Delegates the call to the method
Resumes the client's transaction after the method completes
If the client is not associated with a transaction, the container starts a new transaction before running the method.
You should use the RequiresNew attribute when you want to ensure that the method always runs within a new transaction.
Reference: The Java EE 5 Tutorial, Container-Managed Transactions