My session beans call other bean methods within a transaction. Using bean-managed transactions, how should I take care of commit and rollback ?
Location: http://www.jguru.com/faq/view.jsp?EID=62121 Created: Jun 2, 2000 Modified: 2000-09-12 15:55:36.874 Author: Siva Visveswaran (http://www.jguru.com/guru/viewbio.jsp?EID=46210) Question originally posed by Shalabh Nigam (http://www.jguru.com/guru/viewbio.jsp?EID=47481 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.
Related Questions
- If my session bean with single method insert record into 2 entity beans, how can know that the process is done in same transaction (the attributes for these beans are Required)?
- The EJB specification says that we cannot use Bean Managed Transaction in Entity Beans. Why?
- Why would a session bean use bean-managed transactions?