Book Home Enterprise JavaBeans Search this book

B.2. Session Beans

B.2.1. Stateless Session Beans

figure

Figure B-6. Life cycle state diagram of the stateless session bean

figure

Figure B-7. Creation and removal of the stateless session bean

Table B-3 and Table B-4 summarize the operations that are legal for a stateless session bean.

Table B-3. Allowed Operations for Stateless Session Beans in EJB 1.1

Allowed Operations

Method

Container-Managed Transactions

Bean-Managed Transactions

setSessionContext()

EntityContext methods:

getEJBHome()

JNDI ENC contexts:

Properties java:comp/env

EntityContext methods:

getEJBHome()

JNDI ENC contexts:

Properties java:comp/env

ejbCreate()

ejbRemove()

EntityContext methods:

getEJBHome()

getEJBObject()

JNDI ENC contexts:

Properties java:comp/env

EntityContext methods:

getEJBHome()

getEJBObject()

getUserTransaction()

JNDI ENC contexts:

Properties java:comp/env

business methods

EntityContext methods:

getEJHome()

getCallerPrincipal()

isCallerInRole()

getRollbackOnly()

setRollbackOnly()

getEJObject()

JNDI ENC contexts:

Properties java:comp/env

Resource Managers java:comp/env/jdbc

EJB references java:comp/env/ejb

EntityContext methods:

getEJHome()

getCallerPrincipal()

isCallerInRole()

getEJObject()

getUserTransaction()

JNDI ENC contexts:

Properties java:comp/env

Resource Managers java:comp/env/jdbc

EJB references java:comp/env/ejb

ejbActivate()

ejbPassivate()

Not Supported

(stateless beans do not use these methods)

Not Supported

(stateless beans do not use these methods)

Table B-4. Allowed Operations for Stateless Session Beans in EJB 1.0

Allowed Operations

Method

Container-Managed Transactions

Bean-Managed Transactions

setSessionContext()

EntityContext methods:

getEnvironment()

getEJBHome()

EntityContext methods:

getEnvironment()

getEJBHome()

ejbCreate()

ejbRemove()

EntityContext methods:

getEnvironment()

getEJBHome()

getEJBObject()

EntityContext methods:

getEnvironment()

getEJBHome()

getEJBObject()

getUserTransaction()

business methods

EntityContext methods:

getEnvironment()

getEJHome()

getCallerPrincipal()

isCallerInRole()

getRollbackOnly()

setRollbackOnly()

getEJObject()

EntityContext methods:

getEnvironment()

getEJHome()

getCallerPrincipal()

isCallerInRole()

getEJObject()

getUserTransaction()

ejbActivate()

ejbPassivate()

Not Supported

(stateless beans do not use these methods)

Not Supported

(stateless beans do not use these methods)

B.2.2. Stateful Session Beans

figure

Figure B-8. EJB 1.1 stateful session bean life cycle

figure

Figure B-9. EJB 1.0 life cycle state diagram of the stateful session bean life cycle

figure

Figure B-10. EJB 1.1 life cycle of a stateful session bean with session synchronization interface

figure

Figure B-11. EJB 1.0 life cycle of the stateful session bean with session synchronization interface

figure

Figure B-12. Creation and removal of stateful session beans

figure

Figure B-13. Activation process in stateful session beans

figure

Figure B-14. Transaction notification in SessionSynchronization session beans

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.

Table B-5. Allowed Operations for Stateful Session Beans in EJB 1.1

Allowed Operations

Method

Container-Managed Transactions

Bean-Managed Transactions

setSessionContext()

EntityContext methods:

getEJBHome()

JNDI ENC contexts:

Properties java:comp/env

EntityContext methods:

getEJBHome()

JNDI ENC contexts:

Properties java:comp/env

ejbCreate()

ejbRemove()

ejbActivate()

ejbPassivate()

EntityContext methods:

getEJBHome()

getCallerPrincipal()

isCallerInRole()

getEJBObject()

JNDI ENC contexts:

Properties java:comp/env

Resource Managers java:comp/env/jdbc

EJB references java:comp/env/ejb

EntityContext methods:

getEJBHome()

getCallerPrincipal()

isCallerInRole()

getEJBObject()

getUserTransaction()

JNDI ENC contexts:

Properties java:comp/env

Resource Managers java:comp/env/jdbc

EJB references java:comp/env/ejb

business methods

EntityContext methods:

getEJHome()

getCallerPrincipal()

isCallerInRole()

getRollbackOnly()

setRollbackOnly()

getEJObject()

JNDI ENC contexts:

Properties java:comp/env

Resource Managers java:comp/env/jdbc

EJB references java:comp/env/ejb

EntityContext methods:

getEJHome()

getCallerPrincipal()

isCallerInRole()

getEJObject()

getUserTransaction()

JNDI ENC contexts:

Properties java:comp/env

Resource Managers java:comp/env/jdbc

EJB references java:comp/env/ejb

afterBegin()

beforeCompetion()

EntityContext methods:

getEJHome()

getCallerPrincipal()

isCallerInRole()

getRollbackOnly()

setRollbackOnly()

getEJObject()

JNDI ENC contexts:

Properties java:comp/env

Resource Managers java:comp/env/jdbc

EJB references java:comp/env/ejb

Not Supported

(bean-managed transaction beans can not implement the SessionSynchronization interface)

afterCompletion()

EntityContext methods:

getEJBHome()

getCallerPrincipal()

isCallerInRole()

getEJBObject()

JNDI ENC contexts:

Properties java:comp/env

Not Supported

(bean-managed transaction beans can not implement the SessionSynchronization interface)

Table B-6. Allowed Operations for Stateful Session Beans in EJB 1.0

Allowed Operations

Method

Container-Managed Transactions

Bean-Managed Transactions

setSessionContext()

EntityContext methods:

getEnvironment()

getEJBHome()

EntityContext methods:

getEnvironment()

getEJBHome()

ejbCreate()

ejbRemove()

ejbActivate()

ejbPassivate()

EntityContext methods:

getEnvironment()

getEJBHome()

getCallerPrincipal()

isCallerInRole()

getEJBObject()

EntityContext methods:

getEnvironment()

getEJBHome()

getCallerPrincipal()

isCallerInRole()

getEJBObject()

getUserTransaction()

business methods

EntityContext methods:

getEnvironment()

getEJHome()

getCallerPrincipal()

isCallerInRole()

getRollbackOnly()

setRollbackOnly()

getEJObject()

EntityContext methods:

getEnvironment()

getEJHome()

getCallerPrincipal()

isCallerInRole()

getEJObject()

getUserTransaction()

afterBegin()

beforeCompetion()

EntityContext methods:

getEnvironment()

getEJHome()

getCallerPrincipal()

isCallerInRole()

getRollbackOnly()

setRollbackOnly()

getEJObject()

Not Supported

(bean-managed transaction beans can not implement the SessionSynchronization interface)

afterCompletion()

EntityContext methods:

getEnvironment()

getEJBHome()

getCallerPrincipal()

isCallerInRole()

getEJBObject()

Not Supported

(bean-managed transaction beans can not implement the SessionSynchronization interface)

B.2.3. EJB 1.1: Interactions Between Exceptions and Transactions

Table B-7 summarizes what happens to a transaction if an exception is thrown while the transaction is in process.

Table B-7. Exceptions and Transactions

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 =

Container

transaction-attribute =

Required |

Mandatory |

Supports |

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 =

Container

transaction-attribute =

Required |

Requires New

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 =

Container

transaction-attribute =

Never |

Not Supported |

Supports |

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 =

bean

transaction-attribute =

Bean-Managed Transaction beans do not use transaction attributes.

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.

Rethrow RemoteException.

Receives the RemoteException.

The client's transaction is not affected.



Library Navigation Links

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

This HTML Help has been published using the chm2web software.