My session beans call other bean methods within a transaction. Using bean-managed transactions, how should I take care of commit and rollback ?
Created May 4, 2012
Siva Visveswaran There are two steps here:
1. Coding step:
public class exBean implements SessionBean { EJBContext ec; javax.transaction.UserTransaction utxn; . . . utxn = ec.getUserTransaction(); utxn.begin(); // do all your txn stuff // getting DB connections, updates, other bean methods, etc. . . utxn.commit(); }
Note you have to begin a txn before opening dB connections and close connections before committing.
2. Deployment step:
- Your app server must support a JTS for distributed txns. Most do.
- Verify there is no conflict with the bean transaction properties in calling beans.