Configuring CMP Mappings

See Also

If you are deploying to the GlassFish Server, the CMP mappings for your EJB module are specified in the sun-cmp-mappings.xml descriptor file in the module's src/conf directory. You use the XML editor to configure CMP mappings in sun-cmp-mappings.xml.

You may need to change the CMP mappings of your entity beans in the following situations:

To edit CMP mappings in sun-cmp-mappings.xml:

  1. In the Projects window, expand the Configuration Files node for your EJB module and double-click sun-cmp-mappings.xml.
  2. Edit the file and validate the XML.
  3. Save your changes.

Mapping Entity Beans to Tables

When you map the beans in sun-cmp-mappings.xml, you specify the schema and the primary table for each bean. Each bean must be mapped to at least one table within a single database schema. You can also map a bean to a secondary table. All beans related by container-managed relationships must be mapped to tables in the same schema.

Mapping Fields to Columns

When you map CMP beans to a database, the CMP fields in each entity bean map to columns in either the primary or a secondary table. CMP fields can also be mapped to multiple database columns.

If you map a field to more than one column, all columns will be updated with the value of the first column listed. Therefore, if the value of one of the columns is changed outside of an EJB application, the value will only be read if the change was made to that first column. Writing a value to the database overwrites any conflicting changes made to any other columns.

Mapping Relationship Fields

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.

See Also
About EJB 2.1 CMP Mappings
Generating CMP Entity Beans from a Database
Obtaining a Database Schema

Legal Notices