After you create an initial map, you can use the Mapping Editor
to map a bean element to a table element.
- In the Enterprise Beans pane of the Mapping editor, select an enterprise
bean element that you want to map.
- In the Tables pane of the Mapping editor, select the table element
that you want to map the enterprise bean element to.
- Right-click one of the selected elements and click Create
Mapping from the pop-up menu. The mapping is created and is listed
in the Outline view of the J2EE perspective and in the Overview pane of the
Mapping editor.
Tips for creating mappings:
- If an enterprise bean requires mappings from more than one table (secondary
table maps), you can select multiple tables. In order to create this type
of map, the tables must have foreign-key relationships to each
other.
- Select Match by Name or Match by Type to
create mappings based on name matches or type matches.
- You can also create maps by dragging and dropping between the different
panes in the editor. Drag and drop is only supported in the "direction" of
the map. For example, if the map was created from a "top-down" operation,
then dragging an enterprise bean onto a database is permitted. The following
drag and drop operations are allowed: Dragging an enterprise bean onto a
table creates a map between the two. Dragging a bean onto a DB creates a corresponding
table and columns, and maps it to the bean and attributes.
- The roles of each relationship should be mapped to a corresponding foreign-key.
You can select either role and the other role will be mapped automatically.
- You know that all maps are complete by making sure that all EJB elements
are mapped.
- Persistence code for your enterprise beans can be generated by right-clicking
the enterprise bean and selecting Deploy from the pop-up
menu.
- The Mapping editor allows you to map a composed type to multiple columns
in different tables. This will cause errors in the generation of deployment
code. Ensure that all columns within the composed type mapping belong to the
same table.
- When a CMP entity bean is deleted, any mappings related to this bean will
not be automatically removed. When the Mapping editor is opened on these files
after an entity bean is deleted, the mappings will be removed. This is expected
behavior. You will need to open the Mapping editor prior to generating deployment
code.