 


Table B-3 and Table B-4 summarize the operations that are legal for a stateless session bean.
| Allowed Operations | ||
|---|---|---|
| Method | Container-Managed Transactions | Bean-Managed Transactions | 
| setSessionContext() | EntityContext methods: 
 JNDI ENC contexts: 
 | EntityContext methods: 
 JNDI ENC contexts: 
 | 
| ejbCreate() ejbRemove() | EntityContext methods: 
 JNDI ENC contexts: 
 | EntityContext methods: 
 JNDI ENC contexts: 
 | 
| business methods | EntityContext methods: 
 JNDI ENC contexts: 
 | EntityContext methods: 
 JNDI ENC contexts: 
 | 
| ejbActivate() ejbPassivate() | Not Supported (stateless beans do not use these methods) | Not Supported (stateless beans do not use these methods) | 
| 
 | Allowed Operations | |
|---|---|---|
| Method | Container-Managed Transactions | Bean-Managed Transactions | 
| setSessionContext() | EntityContext methods: 
 | EntityContext methods: 
 | 
| ejbCreate() ejbRemove() | EntityContext methods: 
 | EntityContext methods: 
 | 
| business methods | EntityContext methods: 
 | EntityContext methods: 
 | 
| ejbActivate() ejbPassivate() | Not Supported (stateless beans do not use these methods) | Not Supported (stateless beans do not use these methods) | 







Table B-5 and Table B-6 summarize the operations that are legal for a stateful session bean in EJB 1.1 and 1.0.
| 
 | Allowed Operations | |
|---|---|---|
| Method | Container-Managed Transactions | Bean-Managed Transactions | 
| setSessionContext() | EntityContext methods: 
 JNDI ENC contexts: 
 | EntityContext methods: 
 JNDI ENC contexts: 
 | 
| ejbCreate() ejbRemove() ejbActivate() ejbPassivate() | EntityContext methods: 
 JNDI ENC contexts: 
 | EntityContext methods: 
 JNDI ENC contexts: 
 | 
| business methods | EntityContext methods: 
 JNDI ENC contexts: 
 | EntityContext methods: 
 JNDI ENC contexts: 
 | 
| afterBegin() beforeCompetion() | EntityContext methods: 
 JNDI ENC contexts: 
 | Not Supported (bean-managed transaction beans can not implement the SessionSynchronization interface) | 
| afterCompletion() | EntityContext methods: 
 JNDI ENC contexts: 
 | Not Supported (bean-managed transaction beans can not implement the SessionSynchronization interface) | 
Table B-7 summarizes what happens to a transaction if an exception is thrown while the transaction is in process.
| Transaction Scope | Transactional Type Attributes | Exception Thrown | Container's Action | Client's View | 
|---|---|---|---|---|
| Client Initiated Transaction 
 Transaction is started by the client (application or bean) and is propagated to the bean method. | transaction-type = 
 transaction-attribute = 
 | Application Exception | If the bean invoked EJBContext.setRollbackOnly(), then mark the client's transaction for rollback. Rethrow Application Exception. | Receives the Application Exception. The client's transaction may or may not have been marked for rolled back. | 
| 
 | 
 | System Exception | Mark the client's transaction for roll back. Log the error. Discard the instance. Rethrow TransactionRollbackException. | Receives the TransactionRollbackException The client's transaction has been rolled back. | 
| Container Initiated Transaction 
 The transaction started when the bean's method was invoked and will end when method completes. | transaction-type = 
 transaction-attribute = 
 | Application Exception | If bean called EJBContext.setRollbackOnly(), then rollback the transaction and rethrow the Application Exception. If bean didn't explicitly rollback the transaction, then attempt to commit the transaction and rethrow the Application Exception. | Receives the Application Exception. The bean's transaction may or may not have been rolled back. The client's transaction is not affected. | 
| 
 | 
 | System Exception | Roll back the transaction. Log the error. Discard the instance. Rethrow RemoteException. | Receives the RemoteException. The bean's transaction was rolled back. The client's transaction is not affected. | 
| Bean is not part of a transaction The bean was invoked but does not propagate the client's transaction and does not start its own transaction. | transaction-type = 
 transaction-attribute = 
 | Application Exception | Rethrow Application Exception | Receives the Application Exception. The client's transaction is not affected. | 
| 
 | 
 | System Exception | Log the error. Discard the instance. Rethrow RemoteException. | Receives the RemoteException. The client's transaction is not affected. | 
| Bean Managed Transaction. 
 The stateful or stateless session bean use the EJBContext to explicitly manage its own transaction. | transaction-type = 
 transaction-attribute = 
 | Application Exception | Rethrow the Application Exception. | Receive the Application Exception. The client's transaction is not affected. | 
| 
 | 
 | System Exception | Roll back the transaction. Log the error. Discard the instance. | Receives the RemoteException. | 

Copyright © 2001 O'Reilly & Associates. All rights reserved.