My session beans call other bean methods within a transaction. Using bean-managed transactions, how should I take care of commit and rollback ?
Created Jun 2, 2000
Siva Visveswaran There are two steps here:
Note you have to begin a txn before opening dB connections and close connections before committing.
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();
}
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.