Dynamic enlistment in Bean-managed transactions

EJB Server supports dynamic enlistment for Bean-managed transactions, which allows you to create a connection in one method of a stateful Bean, use the connection in another method, and close the connection in a third method.

For a JDBC 2.0 shared connection (PooledConnection), the container manages the single connection’s enlistment and deenlistment in transactions.

For XA connections, the Object Transaction Service libraries need to know all the resources that will participate in a transaction when it starts. If you get an XAConnection before you start a transaction, EJB Server enlists the XAConnection in the transaction. If you start a transaction before you create an XAConnection, EJB Server creates the connection and enlists it in the transaction.

Dynamic enlistment allows you to do this:

conn1 = ds1.getConnection();
// A
user_transaction.begin();
//
conn2 = ds2.getConnection();
conn3 = ds3.getConnection();
// B
conn2.close();
//
user_transaction.commit();
// C
conn3.close();
conn1.close();

Where at these points, the following are true:

You can get only one connection per resource. Each getConnection call for the same database returns the same connection.

WARNING! XA performance diminishes when connections span methods.