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:
- 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.
- In Sun Configuration editor, expand the Sun Configuration node and select
the entity bean you want to map.
- In the CMP Mappings tab, make sure that you have specified the correct primary
and secondary tables.
- Set the property for the CMP field to <map multiple mappings>.
The Map Field to Multiple Columns dialog box opens.
- 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.
- If you do not see the column you want to map, you might need to add
a secondary table to your mapping, or change the primary table you have
selected.
- If no columns are listed, you have not yet mapped a primary table, or
you have mapped a table that has no columns.
- 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