| h<!DOCTYPE html |
| PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html lang="en-us" xml:lang="en-us"> |
| <head> |
| <link rel="stylesheet" type="text/css" href="../../org.eclipse.wst.doc.user/common.css" /> |
| <title>Creating relationships for EJB 2.x beans</title> |
| </head> |
| <body id="tereltwo"><a name="tereltwo"><!-- --></a> |
| |
| <h1 class="topictitle1">Creating relationships for EJB 2.x beans</h1> |
| <div><p>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.</p><div class="skipspace"><div class="note"><span class="notetitle">Note: </span>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.</div> |
| <p>The |
| following image shows the Add Relationship wizard with the Registration_To_Address |
| relationship being created. A single registered user can have multiple shipping |
| addresses on record, so the multiplicity is [0..*]. On the other hand, a shipping |
| address has a [0..1] relationship with the registered user, and the fk_shipaddress |
| role is added to the foreign key.</p> |
| <p><br /><img src="../images/AddRelationship.gif" alt="Screen capture of the Add Relationship wizard." /><br /></p> |
| <p>To |
| create a relationship between two enterprise beans (EJB 2.x):</p> |
| </div> |
| <ol><li class="skipspace"><span>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.</span></li> |
| <li class="skipspace"><span>On the Overview page of the editor, scroll down to the Relationships |
| 2.0 section, and click <span class="uicontrol">Add</span>. The Add Relationship wizard |
| appears.</span> <div class="tip"><span class="tiptitle">Tip: </span>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.</div> |
| </li> |
| <li class="skipspace"><span>In each of the lists of beans, select one enterprise bean.</span></li> |
| <li class="skipspace"><span>In the <span class="uicontrol">Relationship name</span> field accept the |
| suggested name or type a new name for the relationship.</span></li> |
| <li class="skipspace"><span>Modify or accept the generated Role names.</span></li> |
| <li class="skipspace"><span>Specify the multiplicity for each part of the relationship.</span></li> |
| <li class="skipspace"><span>Hover your mouse pointer over either half of the diagram to specify |
| additional role information for each role:</span><ul><li><span class="uicontrol">Navigable</span> means that instances of the other |
| bean in the association can be retrieved using this role</li> |
| <li><span class="uicontrol">Cascade delete</span> means that deletions will cascade |
| to the other relationship role.</li> |
| <li><span class="uicontrol">Foreign Key</span> means that the specified enterprise |
| bean of the relationship holds a foreign key for the other relationship role.</li> |
| </ul> |
| </li> |
| <li class="skipspace"><span>Click <span class="uicontrol">Finish</span>.</span></li> |
| </ol> |
| <div class="skipspace"><p>The following image shows the Registration_To_Address relationship |
| in the Relationships section of the EJB deployment descriptor editor:</p> |
| <p><br /><img src="../images/Relationships.gif" alt="Screen capture of the Add Relationship wizard." /><br /></p> |
| </div> |
| <div class="skipspace">After you create a relationship, you can select the relationship |
| in the deployment descriptor editor and click the <span class="uicontrol">Edit</span> button |
| to modify it, or click the <span class="uicontrol">Remove</span> button to remove |
| the relationship. Deleting the relationship role also deletes the relationship.</div> |
| </div> |
| |
| <div><p><b class="relconceptshd">Related concepts</b><br /> |
| <a href="../topics/ceassoc.html" title="In the EJB tools, you can use the EJB deployment descriptor editor to optionally define a relationship between different enterprise beans.">EJB relationships</a><br /> |
| </p> |
| <p><b class="reltaskshd">Related tasks</b><br /> |
| <a href="../topics/teassoc.html" title="Use the EJB deployment descriptor editor to specify the relationship between two enterprise beans in your EJB module.">Defining bean relationships</a><br /> |
| </p> |
| </div> <br /> |
| (C) Copyright IBM Corporation 2000, 2005. All Rights Reserved. |
| </body> |
| </html> |