
Use this procedure to create the container-managed relationships between your container-managed entity beans.
When you create the container-managed relationship fields, the SAP NetWeaver Developer Studio automatically generates the corresponding accessor methods (get and set accessor methods), through which the relationship fields are accessed. These methods are public and abstract .
The enterprise beans must have been created.
Creating Unidirectional Relationships
The relationship appears as sub-node in the tree structure.
| Property | Description |
|---|---|
|
Name |
The name of the relationship. This name must be unique within the EJB JAR. If you specify a name that is already assigned to another relationship in the same project, the Developer Studio will add an index to the name to distinguish it from the other relationship. |
|
Description |
Optional description of the relationship. |
|
Source/Target |
Contain declarations of the two beans participating in the relationship. |
|
Bean |
Defines names for the corresponding relationship roles. The Source Bean field is disabled and shows the fully qualified name of the bean class of the entity bean in which you create the relationship. From the Target Bean dropdown list box, choose the second bean that will participate in this relationship. |
|
Cardinality |
The cardinality of the relationship. |
|
CMR Field Name |
The name of the cmr-field. This name must begin with a small letter. The SAP NetWeaver Developer Studio will use this name to create the corresponding get and set accessor methods in the bean's source code by capitalizing the first letter of the container-managed relationship field name and adding get or set in front of it. |
|
CMR Field Type |
Specifies the Collection interfaces utilized by the accessor methods if the relationship is one-to-many or many-to-many (that is, this field is enabled only if you have specified Many as the Cardinality of the target bean). Choose between Collection ( java.util.Collection ) or Set ( java.util.Set ). |
The cmr-field, which you have specified when creating the relationship, appears in the CMR Fields tree structure in the Fields tab of the corresponding bean.
Creating Bidirectional Relationships
The Developer Studio for SAP NetWeaver 04 does not support the creation of bidirectional relationships. Therefore, to create a bidirectional relationship by still using the Developer Studio, follow the steps below.
<relationships> ......... <ejb-relation> <description>Test relationship declaration.</description> <ejb-relation-name>MyRelationship</ejb-relation-name> <ejb-relationship-role> <ejb-relationship-role-name>myejb.entity.CMP1Bean</ejb-relationship-role-name> <multiplicity>Many</multiplicity> <relationship-role-source> <ejb-name>CMP1Bean</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>cmrField1</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> <ejb-relationship-role> <ejb-relationship-role-name>myejb.entity.CMP2Bean</ejb-relationship-role-name> <multiplicity>Many</multiplicity> <relationship-role-source> <ejb-name>CMP2Bean</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>cmrField2</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> </ejb-relation> ......... </relationships>
Relationships are specified in the <ejb-relation> element (part of the <relationships> element) in ejb-jar.xml.
To remove a relationship, select it from the tree structure and choose Remove.
See also:
Defining Relationships Between Container-Managed Entity Beans