When a remote client calls an enterprise bean that manages its own transactions, and the network/ server crashes before the result is returned, the client gets a RemoteException but doesn’t know if the transaction succeeded or failed. The client needs to control the transaction to know the outcome.
In client-initiated transactions, the client code (servlet, JSP, other EJB, CORBA client) begins and ends the transaction — not the bean. The bean still uses programmatic or declarative transactions internally, but the outer transaction scope is controlled by the client.
- Client code looks up transaction service (via JTA — Java Transaction API)
- Client calls
begin()to start the transaction - Client calls the enterprise bean’s business method (bean runs within client’s transaction)
- Bean uses either BMT or CMT internally (client’s transaction propagates to bean)
- Client calls
commit()orabort()to end the transaction - If network crashes, client knows the transaction outcome (since it controls it)
- Client knows transaction outcome (unlike when bean manages its own tx)
- Bean still needs BMT or CMT internally — client-initiated is the outer demarcation
- Higher rollback rates in distributed systems (network failures cause rollbacks)
- Use sparingly, especially for remote clients over WAN
- Client code can be: servlet, JSP, other EJB, CORBA client, application
- Built from: Transaction Demarcation — the third demarcation style
- Built from: Transactions — client controls transaction boundaries
- Related: CMT vs BMT — bean still uses one of these internally
- Contrasts with: MDB — MDB is asynchronous; client-initiated is synchronous
- Related: Entity Bean Transactions — entity beans must use CMT even when client initiates tx
- Distributed applications have more rollbacks due to network failures
- Client must have access to JTA (Java Transaction API) to begin/commit
- If the bean also uses BMT internally, there are nested transaction scopes (but not true nested tx per EJB spec)
- Not recommended for remote clients over unreliable networks (high rollback rate)