Show TOC Start of Content Area

Procedure documentation Creating Beans' Relationships  Locate the document in its SAP Library structure

Use

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.

Prerequisites

The enterprise beans must have been created.

Procedure

Creating Unidirectional Relationships

       1.      Select the container-managed entity bean that will have the cmr-filed for manipulating the relationship and from the context menu choose Open

       2.      In the right-hand pane, choose the Relations tab

       3.      Select Relationships and choose Add.

The relationship appears as sub-node in the tree structure.

       4.      Enter the following data:

 

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 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

Caution

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.      Create 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 to the role declaration of the second bean (that is, the bean in which you have created the get and set accessor methods in step 2). The result should look like the following code excerpt:

<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>

 

Result

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

Mapping Relationships

 

 

End of Content Area