Enterprise beans in applications

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 application server 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 other types of persistent storage. Entity beans with bean-managed persistence 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 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.

WebSphere V5.0 supports both the EJB 1.1 and EJB 2.0 specifications. New in the Enterprise JavaBeans (EJB) specification, version 2.0, message-driven beans 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. For more information on message-driven beans, see Message-driven beans in applications.

Beans that require data access use data sources, which are administrative resources that define pools of connections to persistent storage mechanisms. Perform these steps to use enterprise beans in your enterprise application solutions:

  1. Design a J2EE application and the enterprise beans that it needs.
  2. Develop enterprise beans.
  3. Prepare for assembly. For your EJB 2.x-compliant entity beans, decide on an appropriate access intent policy. For more information, see Access intent policies.
  4. Assemble the beans into one or more EJB modules. For more information, see Assemble EJB modules. This includes securing EJB applications.
  5. Assemble the modules into a J2EE application.
  6. For a given application server, update the EJB container configuration if needed for the application to be deployed. For more information about EJB containers, see EJB containers.
  7. Deploy the application in an application server. For more information, see the Install and uninstall applications topic in Administration.
  8. Test the modules. As needed, debug problems with the container.

For information on the ejbdeploy tool, see EJB Deploy Tool.

Note: Special coding considerations are required when using the pass-by-reference option for enterprise beans with remote interfaces. For more information, see Restrictions for using the pass-by-reference option for enterprise beans with remote interfaces.

Enhancements for WAS Version 5.0.2 (and later)

Batch commands for container managed persistence
This topic describes the new support in WAS Version 5.0.2 to defer ejbStore, ejbCreate, ejbRemove or the equivalent database persistence requests (insert, update, or delete) until they are required.

Explicit invalidation in the Persistence Manager Cache
This topic describes the new support in WAS Version 5.0.2 to allow an application to inform WAS that any cached version of a CMP entity bean's data is stale and no longer matches what is in the database. The data is then invalidated.

Deferred Create for container managed persistence
This topic describes the new support in WAS Version 5.0.2 to defer ejbCreate until it is required for CMP entity beans. By doing this you can reduce two round trips for the newly created entity bean.