Show TOC Start of Content Area

Procedure documentation Mapping Relationships  Locate the document in its SAP Library structure

Use

Use this procedure to specify the mapping of container-managed relationships to the underlying database. The mapping is described in the J2EE Engine-specific deployment descriptor – persistent.xml.

Prerequisites

The relationships have been created.

Procedure

...

       1.      Open the persistent.xml.

       2.      From the right-hand pane, choose the Relationships tab.

The relationships that you have created are displayed in a tree structure in the left-hand pane of the Relationships tab. The names of the roles (that is, the fully qualified names of the entity beans, participating in the relationship) are displayed as sub-nodes of the corresponding relationship name. If the primary key fields of a bean are to be mapped to a foreign key column in the table of the other bean in the relationship, then these primary key fields are also displayed in the tree structure.

Note

For one-to-one relationships, the foreign key columns can be in either of the two tables. Therefore, you can choose the bean whose primary key will be mapped to foreign key columns in the table to which the other entity bean is mapped.

For one-to-many relationships, the foreign key columns are in the table of the bean whose multiplicity in the relationship is Many. Therefore, the tree structure contains the primary key of the bean whose multiplicity in the relationship is One.

For many-to-many relationships, the primary keys of both entity beans are displayed, as both primary keys are mapped to foreign key columns in a helper table.

       3.      Select the relationship that you want to map

The right-hand pane displays the relationship type, that is, one-to-one, one-to-many, or many-to-many. This field is disabled and you cannot change the cardinality of the relationship in this screen.

       4.      Choose This graphic is explained in the accompanying text Select table from the data dictionary to map your many-to-many relationship to a helper table.

A dialog box appears, where you can choose from the tables created in the Java Dictionary.

Note

This option is disabled for one-to-one and one-to-many relationships, as they do not need a helper table.

The helper table is mandatory for a many-to-many relationship. Its columns are foreign key columns referencing the primary key columns of the two tables to which the beans participating in the relationship are mapped.

       5.      Select one of the relationship roles in the relationship that you want to map.

The right-hand pane displays the EJB name of the bean in this role and the name of the cmr-field on its side. These names cannot be modified on this screen.

                            a.      Choose the placement of the foreign key columns for the relationship:

                                                  i.       Mapped to foreign key columns in the table of the other bean – the primary key fields of the bean in the selected role will be mapped to foreign key columns in the other bean.

                                                ii.       Not used to describe this relation; this side contains the foreign key columns – specifies that the table of the bean in this role contains the foreign key columns. If you choose this option, you must also specify the database type of these foreign key columns, that is NoKey or ForeignKey.

This option is available only for the roles in a one-to one relationship. In a one-to-many relationship, these options are predetermined, as the foreign key columns are always in the table of the bean, whose multiplicity is Many. In this pane, you can only choose the database type of the foreign key columns. For many-to-many relationships, these options are disabled.

       6.      Map the primary key fields to the foreign key columns

In one-to-one and one-to-many relationships, the primary key fields are displayed in the tree structure as sub-nodes to the bean that contains the foreign key columns.

In many-to-many relationships, the primary key fields are displayed as sub-nodes to their own bean.

                            a.      Select the primary key field that you want to map

                            b.      From the Column name drop-down list in the right-hand pane, choose the column that will be the foreign key column for the selected primary key field

If your primary key is compound, repeat the same steps for all fields in your primary key.

 

See also:

Object/Relational Mapping Rules

 

 

End of Content Area