Entity beans with container-managed persistence can participate in relationships between each other. This enables you to develop complex applications consisting of interrelated container-managed entity beans.
Container-managed relationships are realized using cmr-fields described in the deployment descriptor(s). Entity beans access their related container-managed entity beans using get and set accessor methods for these fields.
Container-managed entity beans can access each other only through local interfaces. If a bean does not provide a local view, it cannot be related by other container-managed entity beans.
Relationships can be unidirectional or bidirectional.
In unidirectional relationships, only one of the entity beans participating in the relationship has a cmr-field on the side that refers to the other container-managed entity bean. This means that the relationship can be navigated in one direction only. However, even though an entity bean participates in a unidirectional relationship, it can still be affected if you change that relationship. Container-managed entity beans, which do not provide a local view, can only participate in a unidirectional relationship from themselves to other entity beans.
In bidirectional relationships, both entity beans have a cmr-field that refers to the other entity bean. In this way these relationships can be navigated in both directions.
Container-managed relationships can be one-to-one, one-to many, and many-to-many depending on the number of entities of each bean class that can participate in a container-managed relationship.
Follow the procedures below to create and define the container-managed relationships between your entity beans using the SAP NetWeaver Developer Studio:
1. Creating Beans’ Relationships – use this procedure to define the relationship in the ejb-jar.xml deployment descriptor of the entity beans participating in the relationship.
2. Defining Relationships Between Container-Managed Entity Beans – use this procedure to define additional deployment properties of the container-managed relationship. These properties are also stored in the ejb-jar.xml.
3. Mapping Relationships – use this procedure to map the container-managed relationships to the underlying database. This mapping is specified in the persistent.xml deployment descriptor.