Mapping Relationship Fields

See Also

When you have foreign-key relationships between database tables, you usually want to preserve those relationships in the CMP beans mapped to those tables. Container-managed relationships (CMR) determine how relationships between mapped CMP beans are stored in the database. CMRs enable navigation from one bean to another, in the same way that a foreign key enables navigation from one table to another.

If you are deploying to the Sun Java System Application Server, you can configure CMRs in the Sun Configuration editor. If you are deploying to a different application server, you have to configure CMRs yourself in the server-specific deployment descriptors.

To edit your relationship field mappings:

  1. Make sure you have configured the CMRs in the general deployment descriptors.
  2. In the Projects window, expand the Configuration Files node for your EJB module and double-click sun-cmp-mappings.xml or sun-ejb-jar.xml.
    • If either sun-cmp-mappings or sun-ejb-jar.xml are open in the text mode, you cannot open the visual editor. You first have to close the text mode tabs in the Source Editor.
  3. In Sun Configuration editor, expand the Sun Configuration node and select the entity bean you want to map.
  4. Select <map relationship field> in the Mapped Column column for the CMR field. The Map Relationship Field wizard opens.
  5. Follow the steps in the wizard.

In the Field Mappings table in the IDE, persistent fields with mapped relationships are indicated by <mapped relationship> in the Mapped Column column. When you create or modify field mappings in the Sun Configuration editor, the IDE makes these changes in the sun-cmp-mappings.xml file. The modified sun-cmp-mappings.xml file is copied to the Sun Java System Application Server when the application is deployed.

See Also
About EJB 2.1 CMP Mappings
Generating CMP Entity Beans from a Database
Obtaining a Database Schema
Configuring CMP Mappings
Mapping CMP Fields to Multiple Columns

Legal Notices