Java Reference
In-Depth Information
Remember that business logic is built into the YachtSessionEJB that you cannot accelerate a
stopped yacht. You must start the yacht and then speed it up. You cannot stop a yacht that is running
too fast. You must slow it down to certain speed before stopping it. If you want to add business logic,
you can revisit the YachtSessionEJB code listed in Chapter 20 and make any modification you need.
Figure 22-2: Possible output screen of your yacht-session client
This example application is simplified to demonstrate the fundamentals of CMP EJB. However, an
important feature of CMP entity bean brought by EJB 2.0 is missing: the container managed relationship.
You will learn it in the next section .
Container-Managed Relationship
The entity beans you have seen so far in this topic are detached objects that do not relate with each
other. This type of entity bean has only limited use because in real life objects are often linked and
depend upon each other. This kind of behavior has always existed in databases through primary keys
and foreign keys. With EJB 1.1, CMP entity beans had no easy way of representing the natural
interaction between entity objects. This has partially contributed to the slow adoption of CMP entity
beans in the early stage. To address this problem, the EJB 2.0 specification introduces a way to support
simple and complex relationships by introducing the container-managed relationship through the
relationship fields .
Relationship Field
A relationship field is like a foreign key in a database table — it identifies a related bean. Like a
persistent field, a relationship field is virtual and is defined in the enterprise-bean class with access
methods. But unlike a persistent field, a relationship field does not represent the bean's state. For
example, each yacht has an engine. Assume an EngineEJB is developed; it has a one-to-one
relationship with the YachtEJB you have written. To model YachtEJB 's relationship to EngineEJB , it
has a relationship field: engine . In the deployment descriptor, you specify this relationship as follows:
<ejb-relation>
<ejb-relation-name>Yacht-Engine</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Yacht-Has-Engine</ejb-relationship-role-
name>
<multiplicity>one</multiplicity>
Search WWH ::




Custom Search