Chapter 9 Creating Enterprise JavaBean Clients


Managing transactions

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:

 


Copyright © 2000 Sybase, Inc. All rights reserved.