!--a11y-->
Creating Beans' Relationships 
Use this procedure to create the container-managed relationships between your container-managed entity beans.
When you create the container-managed relationship fields, the 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 bean must have been created.
1. Select the container-managed entity bean and from the context menu choose Open
1. In the right-hand pane, choose the Relations tab
2. Select Relations with EJB in role 1 or Relations with EJB in role 2 according to which part of the relationship your entity bean will represent, and choose Add.
The relationship appears as sub-node in the tree structure.
3. Enter the following data:
Property |
Description |
Name |
The name of the relationship. This name must be unique within the EJB JAR. |
Description |
Optional description of the relationship. |
Source Target |
Contain declarations of the two beans participating in the relationship. |
Bean |
Defines a name for the corresponding role that is unique within the relationship declaration. Different relationships can use the same name for a role. The NetWeaver Developer Studio assigns the fully qualified name of the bean class to that field. |
Cardinality |
The cardinality of the relationship. |
CMR Field Name |
The name of the cmr-field for the corresponding entity bean. This name must begin with a small letter. If your relationship is bidirectional, you must define cmr-fields for both beans participating in the relationship, that is, both in the Source and Target declarations. The 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. Choose between Collection (java.util.Collection) or Set (java.util.Set). |

The Developer Studio for 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.
...
1. Create a unidirectional relationship in one of the beans, which will participate in the bidirectional relationship
2. Add the get and set accessor methods for this relationship in the source code of the second bean in the relationship
3. Edit the ejb-jar.xml by modifying the code generated for this relationship:
a. Add the corresponding cmr-field, for which you have created the get and set accessor methods in step 2, that is, add the following code in the definition of the created relationship:
<cmr-field> <cmr-field-name>yourField</cmr-field-name> </cmr-field> |
The cmr-fields, which you have specified when creating the relationship, appear in the Fields tab in the CMR Fields tree structure of the corresponding bean.
Relationships are specified in the <ejb-relation> element (part of the <relationships> element) in ejb-jar.xml.
See also:
Defining Relationships Between Container-Managed Entity Beans
