Chapter 8: Creating Enterprise JavaBeans Clients
EJB clients can begin transactions using the javax.transaction.UserTransaction interface. Obtain an instance from the initial naming context by resolving the name javax.transaction.UserTransaction. For example:
import javax.transaction.*; import javax.naming.*; Context ctx; ... ctx has been initialized ... UserTransaction uTrans = (UserTransaction) ctx.lookup( "javax.transaction.UserTransaction");
You can call the begin(), commit(), and rollback() methods to begin and end transactions. You can enlist multiple component methods in a transaction, with these restrictions:
Each method must allow inheritance of an existing transaction context. That is, the method’s transaction attribute must be Supports, Requires, or Mandatory. Methods with other transaction attributes run outside the scope of your transaction. See “Component properties: Transactions” for more information on transaction attributes.
All components must be on the same server, and all must use the same transaction coordinator.
All methods must be invoked by the thread that began the transaction.
|Copyright © 2005. Sybase Inc. All rights reserved.|