Mapping CMP Fields to Multiple Columns

See Also

Sometimes you want to map a CMP field to multiple database columns. If you are deploying to the Sun Java System Application Server, you can configure the CMP mappings in the Sun Configuration editor. If you are deploying to another application server, you have to edit the CMP mappings yourself in the server-specific deployment descriptors.

To map a field to more than one column:

  1. 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.
  2. In Sun Configuration editor, expand the Sun Configuration node and select the entity bean you want to map.
  3. In the CMP Mappings tab, make sure that you have specified the correct primary and secondary tables.
  4. Set the property for the CMP field to <map multiple mappings>. The Map Field to Multiple Columns dialog box opens.
  5. In the left pane, select the columns you want mapped to the field and click Add. The selected columns appear in the right pane. The left pane lists the available columns from the tables mapped to the bean.
  6. Use Move Up/Move Down to change the order of the columns in the right pane.

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.

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

Legal Notices