Enterprise beans

 


Overview

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:

  1. entity
  2. session
  3. message-driven

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

 

Entity beans

Entity beans store permanent data. Entity beans with container-managed persistence require connections to a form of persistent storage. This storage might be a database, an existing legacy application, a file, or other types of persistent storage. Entity beans with BMP manage permanent data in whichever manner is defined in the bean code. This can include writing to databases or XML files, for example.

 

Session beans

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

Message-driven Beans (MDBs) enable asynchronous message servicing. The EJB container and a 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 an MDB instance. MDBs 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.


 

Data sources
Message-driven beans - components
Using enterprise beans in applications
Enterprise beans: Links