Getting Started with Enterprise JavaBeans™

G

Session Beans

Tutorial Home Section Home Previous Section Next

Get

Get

Overview

     Session beans are reusable components that have conversations or sessions with clients. In many ways, session beans are the workhorses of the EJB family, at various times providing direct functionality, managing or controlling interaction with resources and other beans, and acting as a façade or liaison for cooperating beans. Their lifetimes and life cycles are relatively short and dependent on the client. Session beans are non-persistent and live no longer than the client and possibly less. Under the hood, the container may actually reuse session beans, but from the client's perspective, once they are gone, they are permanently gone. There are two types of session beans, stateless and stateful, and they have distinctly different types of relationships with their clients. The container is made aware of the type of the session bean through a deployment descriptor entry.

Figure SB-1: The javax.ejb.SessionBean interface
The javax.ejb.SessionBean interface

     When you write any session bean, you must implement the the javax.ejb.SessionBean interface. All beans have an associated context; for session beans the container calls setSessionContext() after instance creation, which allows the bean to obtain a reference to the session context. The ejbActivate() and ejbPassivate() methods are only invoked on stateful session beans. ejbRemove() is called at the end of a session bean's lifetime for any cleanup before destruction.



Tutorial Home Section Home Previous Section Next