
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.
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.
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.
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.
A dialog box appears, where you can choose from the tables created in the Java Dictionary.
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.
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.
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.
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.
If your primary key is compound, repeat the same steps for all fields in your primary key.
See also: