Enterprise beans

An enterprise bean is a Java component that can be combined with other resources to create J2EE applications. There are three types of enterprise beans, entity beans, session beans, and message-driven beans.

All beans reside in EJB containers, which provide an interface between the beans and the appserver on which they reside.

Entity beans store permanent data. Entity beans with container-managed persistence (CMP) require connections to a form of persistent storage. This storage might be a database, an existing legacy application, a file, or another type of persistent storage. Entity beans with bean-managed persistence manage permanent data in whichever manner is defined in the bean code. For example, they can write data to databases or XML files

Session beans do not require database access, although they can obtain it indirectly as needed through entity beans. Session beans can also obtain direct access to databases (and other resources) through the use of resource references. Session beans can be either stateful or stateless.

Message-driven beans are new in version 2.0 of the Enterprise JavaBeans (EJB) specification. They enable asynchronous message servicing. The EJB container and a Java Message Service (JMS) provider work together to process messages. When a message arrives from another application component through JMS, the EJB container forwards it through an onMessage() call to a message-driven bean instance, which then processes the message. In other respects, message-driven beans are similar to stateless session beans.

Beans that require data access use data sources, which are administrative resources that define pools of connections to persistent storage mechanisms.

For more information about enterprise beans, see "Resources for learning."


Related concepts
Data sources
Message-driven beans - components
Related tasks
Using enterprise beans in applications
Related reference
Enterprise beans: Resources for learning