|
The Enterprise JavaBeans (EJB ) architecture is a component architecture for developing and deploying component-based distributed business applications. The EJB specification defines the responsibilities of both component developers and EJB server and container vendors. The EJB 2.0 specification builds upon and extends the architecture and functionality defined by the earlier EJB 1.0 and 1.1 specifications. This article summarizes the changes introduced by the 2.0 specification. (Note that the 2.0 specification is not yet public, so this article focuses on high level information only.) It provides an early view of the forthcoming EJB changes so that developers can plan accordingly. Keep in mind that the EJB 2.0 specification is not in its final form, and there could be further changes. In brief, the EJB 2.0 specification introduces these new features:
Types of Enterprise BeansThe EJB 2.0 specification introduces a new type of enterprise bean, called a message-driven bean, in addition to session beans and entity beans. Session and entity beans are very much the same as in the earlier EJB architecture. However, there have been changes to how these beans are accessed and used.
Container-Managed Persistence in EJB 2.0The changes to the EJB 2.0 specification principally concern container-managed persistence (CMP). Along with CMP, the 2.0 specification introduces container-managed relationships (CMR). The 2.0 approach to CMP allows multiple entity beans to have container-managed relationships among themselves. The automatic management of relationships, plus the container management of the referential integrity of relationships, is an advancement above the EJB 1.1 specification which allowed you to expose only an entity bean's instance state through its remote interface. The 2.0 approach, with the introduction of local interfaces, offers some significant advantages, especially in terms of greater flexibility. The 2.0 approach to CMP is a lightweight way of doing fine-grained container-managed persistence. It uses a local model that can be more tightly coupled than the remote model, and it avoids the performance overhead of the remote model. It is also closer to the Java programming model, particularly with regards to passing parameters between enterprise beans. If you are familiar with the earlier version of the EJB 2.0 specification, note that the Persistent Manager and the use of dependent objects to model entity bean relationships are both gone. Together, CMP with managed relationships--that is, container-managed persistence at the entity bean level with local interfaces--represents the functionality encompassed by dependent objects. The EJB container performs the persistent manager functionality. CMP and CMR FieldsIn the 1.1 specification, a client stored and accessed persistent data via an entity bean's instance variables. In the current 2.0 specification, instance variables can be designated as
These cmp and cmr fields are defined through the deployment descriptor. The
bean developer also defines Furthermore, the deployment descriptor specifies the relationships between entity beans, and these relationship specifications become the schema definition. Relationships are defined by the bean provider and specified in the deployment descriptor. Then, when the bean is deployed, the bean relationships may be captured in a relational database. For example, a relationship between two beans specified in the deployment descriptor may appear as a foreign key relationship in a relational database. Entity Bean RelationshipsContainer-managed relationships--represented by the cmr fields in the deployment descriptor--support both one-to-one relationships and one-to-many relationships. With one-to-many relationships, the entity bean uses a Java Collection to represent the "many" side. This ability to manage relationships is closely aligned to relationship modelling in relational databases. The EJB container maintains the referential integrity of the entity bean relationships. For example, in a one-to-one relationship, if you change one side of the relationship, the container automatically drops the old relationship and replaces it with the newly formed one-to-one relationship. This relationship functionality is not available to bean implementations adhering to the EJB 1.1 specification. However, the 2.0 specification support continues to 1.1 level enterprise beans. Bean Interfaces and ImplementationAccording to the 2.0 specification, the implementation classes for entity beans that use CMP are now abstract classes. The implementation classes for non-CMP entity beans and session beans are the same as under the 1.1 specification. Session beans and entity beans in 2.0 can have two types of interfaces: a remote interface and a local interface.
Typically, however, a bean will be designed to provide only one or the other interface. Similarly, a bean can have a remote home interface and/or a local home interface. In the 2.0 specification, a bean typically uses its remote interface to expose its methods across the network tier. A bean uses the local interface to expose its methods to other beans that reside within the same container. It is thus possible to directly access a bean through its local interface without the overhead of a remote method call. Local interfaces provide the foundation for container managed relationships among entity beans and session beans. The bean uses the local interface to maintain its references to other beans. For example, entity beans use local interfaces to maintain relationships to other entity beans. They also allow session and entity beans to be tightly coupled with their clients. Using local interfaces, beans can also expose their state and use pass-by-reference to pass their state between related bean instances. Query LanguageThe EJB 2.0 specification also introduces a query language called EJB Query Language, or EJB QL. EJB QL defines query methods--finder and select methods--for entity beans with container-managed persistence, and it is intended to be portable across EJB containers. EJB QL is based on SQL92. However, it has been enhanced to allow querying or navigation
over entity bean relationships. That is, a query can begin with one entity bean and, from
there, navigate to related beans. For example, the query can start with an EJB QL builds on the container-managed relationships specified in the deployment descriptor. The query is specified in the deployment descriptor. The container then generates the QL implementation for the query. For example, in the deployment descriptor, you might have the following query:
A query such as this navigates two relationships: from ConclusionThis article has presents a brief overview of the forthcoming changes to the Enterprise JavaBeans architecture that the EJB 2.0 specification will introduce. Refer to the actual specification for more complete information. Keep in mind that further changes may occur until the time that the specification is released in its final form. About the AuthorBeth Stearns is the principal partner of ComputerEase Publishing, a computer consulting firm she founded in 1982. Her client list includes Sun Microsystems, Inc., Silicon Graphics, Inc., Oracle Corporation, and Xerox Corporation. Among her publications are the "Java Native Interface" chapter in "The Java Tutorial Continued" book in the Addison Wesley Java series, "The EJB Programming Guide" for Inprise Corporation, and "Understanding EDT", a guide to Digital Equipment Corporation's text editor. Most recently, she co-authored with Vlada Matena of the forthcoming Addison Wesley Java series book, "Applying Enterprise JavaBeans: Component-Based Development for the J2EE Platform." Have a question about programming? Use Java Online Support. | |||||||||
|
| ||||||||||||