Create and configure container-managed relationships

Rational Application Developer offers a couple of facilities to streamline the process of both creating and maintaining container-managed relationships (CMRs). You can, for instance, visually create relationships with the UML Diagram Editor, and the environment will automatically generate all the necessary code and deployment descriptor changes. You may, alternatively, edit the deployment descriptor directly, and Rational Application Developer will also generate the appropriate code changes. Finally, you can use the environment's menus to accomplish the same task.

Creating relationships for EJB 2.x beans

Use the Add Relationship wizard to specify the relationship between two enterprise beans in your EJB project or module. The appropriate finder methods are generated to support any relationships that you create.

NOTE: If a relationship exists between one or more CMP beans, changing the key shape of one CMP may result in the related CMPs being regenerated.

The following image shows the Add Relationship wizard with the Customer-Order relationship being created. A single customer can have multiple orders on record, so the multiplicity is [0..*].

Add Relationship - 1

To create a relationship between two enterprise beans (EJB 2.x):

  1. In the Project Explorer view of the J2EE perspective, open the EJB Deployment Descriptor editor for the EJB module that includes the enterprise beans that you want to associate (Chapter2EJB).

  2. On the Overview page of the editor, scroll down to the Relationships section, and click Add .... The Add Relationship wizard appears.

    TIP: When you open the wizard from the Overview page, the beans for both sides of the relationship can be edited. The wizard can also be opened from the Bean page of the editor with a bean selected.

  3. In each of the lists of beans, select one enterprise bean.

  4. In the Relationship name field accept the suggested name or type a new name for the relationship. Click Next.

  5. Modify or accept the generated Role names.

  6. Specify the multiplicity for each part of the relationship.

    Add Relationship - 2

  7. Hover your mouse pointer over either half of the diagram to specify additional role information for each role:

    • Navigable - means that instances of the other bean in the association can be retrieved using this role.

    • Cascade delete - means that deletions will cascade to the other relationship role.

    • Foreign Key - means that the specified enterprise bean of the relationship holds a foreign key for the other relationship role.

  8. Click Finish.

The following image shows the Customer-Order relationship in the Relationships section of the EJB deployment descriptor editor:

Relationship

The following image shows the Customer-Order relationship in the UML Class Diagram editor:

Class Diagram

After you create a relationship, you can select the relationship in the deployment descriptor editor and click the Edit button to modify it, or click the Remove button to remove the relationship. Deleting the relationship role also deletes the relationship.

BOOT.BY - Tech Industry News         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free SCBCD 5.0 Study Guide