Creating Related CMP Entity Beans with the EJB Builder

Creating the Related CMP Entity Beans

  1. Create a new package to hold the CMP entity beans.
  2. Right-click the filesystem you have created for the EJB files and choose New -> Java Package. Name the new package and click Finish.

    The IDE displays the new package in the filesystem.

  3. Right-click the new package node and choose New -> J2EE -> Related CMP Entity EJBs.
  4. The Related CMP Entity Beans wizard opens.

  5. Type entity_bean_nameJAR in the EJB Module Name field.
  6. Select Tables from Database Schema Object in the Source for CMP Entity EJBs radio button box and click Next.
  7. The Select Database Schema Object pane is displayed.

  8. Select the schema node under the filesystem and click Next.
  9. The four tables that you selected previously are listed in the Available Tables list.

  10. Click Add All.
  11. The four tables are moved to the Selected Tables list.

  12. Click Next.
  13. The Edit CMP Entity EJB Data pane is displayed.

  14. For each table listing, select the node, then type a name in the EJB Name field and the same name in the Abstract Schema Name field.
  15. If all the beans you are using are accessed only from the session bean, make sure that Local Interfaces Only is selected in the Component Interfaces radio button box.

  16. For each table listing, expand the node, select the primary key (nameid (PK)) and make any desired changes to the CMP Field Name field.
  17. For each table listing, expand the node, select each field name and choose the appropriate CMP Field Type.
  18. For strings, select java.lang.String, for doubles double, etc.

  19. For each table listing, expand the node, select the relationship node labeled (CMR to name), and make any necessary changes to the EJB Relation Name, Role Name, CMR Field Name, and CMR Type fields.
  20. The entry in the EJB Relation Name should have the form bean1 nameEJB-bean 2 nameEJB.

    The Role Name can match the name of the table listing. The CMR field name refers to the related bean. The Multiplicity field shows the nature of the relationhip, either One or Many. The CMR Type is the variable type.

    For example, in the sample Roster application that ships with Sun ONE Application Server, one EJB relationship is between the TeamEJB and LeagueEJB. For this relationship:

  21. Click Finish.
  22. The infrastructure of your set of related CMP entity beans (the bean classes, their local interfaces and local home interfaces, and the interbean relationships) is generated automatically by the EJB Builder.

Verifying Relationships

After creating related CMP enterprise beans, you can examine their relationships from the IDE Explorer.

  1. Expand a new nameJAR EJB module node and all of its CMP entity bean nodes.
  2. Right-click a relationhship CMR node under the CMP entity bean node and choose Edit EJB Relation.
  3. The Edit EJB Relation editor opens.

  4. Repeat this process for each of the relationships you have created.

Verifying Mappings for CMP Fields and CMP fields

The EJB Builder assigns the correct mappings for the fields in the CMP enterprise beans you create. You can examine the results.

To view mappings for the CMP entity bean fields:

  1. Expand the nameJAR EJB Module nodes and select the included related entity bean node.
  2. In the Properties window, select the Sun ONE AS Mappings tab.
  3. The EJB fields are already mapped. CMP fields of the bean are mapped to corresponding columns in the corresponding database table, where thier values will be stored. CMR fields of the bean are mapped to the corresponding relationship.

  4. Select a field and click the ellipsis (...) button.
  5. The Relationship Mapping editor appears displaying the Initial Setup pane.

    The field's database table linking is shown.

  6. Click Next.
  7. The Map to Key pane is displayed. The columns used in the linking are shown.

  8. If you have made no changes, click Cancel to close the Relationship Mapping editor.

Legal Notices