blob: ae4a319a8a176e06a04b839c5e9d9893cd22bc14 [file] [log] [blame]
<!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>Adding relationship roles to keys</title>
</head>
<body id="teaddroletokey"><a name="teaddroletokey"><!-- --></a>
<h1 class="topictitle1">Adding relationship roles to keys</h1>
<div><p>You can add a relationship role to a key class.</p><div class="skipspace"><p>The relationship role to be added must have the following characteristics:</p>
<ul><li>It is not many-valued.</li>
<li>It is both required and navigable.</li>
<li>It holds a foreign key.</li>
</ul>
<p>Additionally, the enterprise bean to which the key will be added must
be a root bean (does not inherit from a supertype). This is because inherited
beans must use the primary key class of the supertype and therefore the key
class shape cannot be modified.</p>
<p>The following task refers to two enterprise
beans: one that contains a role (<i>this</i> bean) and one represented in
the role (the <i>other</i> bean).</p>
</div>
<ol><li><span>In the Project Explorer view of the J2EE perspective, right-click
the Deployment Descriptor for your EJB project and select <span class="menucascade"><span class="uicontrol">Open
With</span> &gt; <span class="uicontrol">Deployment Descriptor Editor</span></span> to
open the deployment descriptor editor.</span></li>
<li><span>On the <span class="uicontrol">Bean</span> page, select the enterprise
bean that contains the relationship role that you want to add to the key,
and scroll to the Relationships section.</span></li>
<li><span>Click <span class="uicontrol">Add to Key</span>.</span></li>
</ol>
<div class="skipspace"> <p>This action adds the key fields of the other bean to both the
key class and the bean class of this bean. When a role is added to the primary
key, the association is also regenerated.</p>
<p>Be careful when removing beans
from an association. If you have added one of the roles to the key of one
of the beans, the bean with the role in the key must be removed before the
other bean. A database constraint may enforce this (even if the role is not
part of the key). However, if there is no database constraint, problems could
still occur. For example, suppose that you have Customer and Address beans
in a 1:1 association where the customer role of the Address bean holds the
foreign key and the customer role is the primary key of the Address bean.
If you were to remove the Customer bean without first removing the Address
bean, the association maintenance code, while trying to set the Address bean's
customer role foreign-key to null, will also be trying to set the primary
key of the Address bean to null.</p>
</div>
</div>
<div><p><b class="reltaskshd">Related tasks</b><br />
<a href="../topics/teaddsecurityidbean.html" title="Assigning a security identity to a bean is useful when another bean calls that bean. The security identity can be set to use the identity of the caller or the identity of a specific security role.">Adding a security identity (bean level)</a><br />
<a href="../topics/teaddsecurityrole.html" title="You need to add security roles in order to build method permissions.">Defining security roles for EJB modules</a><br />
<a href="../../com.ibm.etools.j2eeapp.doc/topics/tjaddrefsecurityrole.html">Adding security role references</a><br />
</p>
</div> <br />
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.
</body>
</html>