Describing Relationships

CMP entity bean classes are defined using abstract accessor methods that represent virtual persistence and relationship fields. As discussed in Chapter 6, Chapter 7, and Chapter 8, the fields themselves are not declared in the entity classes. Instead, the characteristics of these fields are described in the bean’s deployment descriptor. The abstract persistence schema is the set of XML elements in the deployment descriptor that describe the relationship and persistence fields. By combining the abstract persistence schema with the abstract programming model (i.e., the abstract accessor methods) and a little help from the deployer, the container tool has enough information to map the entity and its relationships with other entity beans.

The relationships between entity beans are described in the <relationships> section of the XML deployment descriptor. The <relationships> section falls between the <enterprise-beans> and <assembly-descriptor> sections. Within the <relationships> element, each entity-to-entity relationship is defined in a separate <ejb-relation> element:

<ejb-jar>
    <enterprise-beans>
    ...
    </enterprise-beans>
    <relationships>
        <ejb-relation>
        ...
        </ejb-relation>
        <ejb-relation>
        ...
        </ejb-relation>
    </relationships>
    <assembly-descriptor>
    ...
    </assembly-descriptor>
</ejb-jar>

Defining relationship fields requires that an <ejb-relation> element be added to the XML deployment descriptor for each entity-to-entity relationship. These <ejb-relation> elements ...

Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.