Chapter 8 Creating J2EE Applications for BEA WebLogic


Using javax.transaction.UserTransaction

To define transaction boundaries in EJB or client code, you must obtain a UserTransaction object and begin a transaction before you obtain a JTS or JDBC database connection. If you start a transaction after obtaining a database connection, the connection has no relationship to the new transaction, and there are no semantics to "enlist" the connection in a subsequent transaction context. If a JTS connection is not associated with a transaction context, it operates similarly to a standard JDBC connection that has autocommit equal to true, and updates are automatically committed to the datastore.

Once you create a database connection within a transaction context, that connection becomes "reserved" until the transaction either commits or rolls back. To maintain performance and throughput for your applications, always ensure that your transaction completes quickly, so that the database connection can be released and made available to other client requests.

Note that you can associate only a single database connection with an active transaction context.

Restriction for Container-Managed EJBs

You cannot use the javax.transaction.UserTransaction method within an EJB that uses container-managed transactions.

 


Copyright (C) 2005. Sybase Inc. All rights reserved.