⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmp6.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<a name="wp83063"> </a><p class="pBody">The Container Managed Relationships table summarizes two relationships: <code class="cCode">TeamEJB-PlayerEJB</code> and <code class="cCode">LeagueEJB-TeamEJB</code>. In the <code class="cCode">TeamEJB-PlayerEJB</code> relationship, <code class="cCode">TeamEJB</code> is designated as EJB A and <code class="cCode">PlayerEJB</code> as EJB B. (This designation is arbitrary--we could have assigned <code class="cCode">PlayerEJB</code> to EJB A and <code class="cCode">TeamEJB</code> to EJB B.)</p><a name="wp83065"> </a><h5 class="pHeading4">Edit Relationship Dialog Box (TeamJAR)</h5><a name="wp83069"> </a><p class="pBody">To view the Edit Relationship dialog box (<a  href="CMP6.html#wp83085">Figure 22-4</a>), on the Relationships tab select a row and click Edit. For example, to view the <code class="cCode">TeamEJB-PlayerEJB</code> relationship, select the row in which the EJB A value is <code class="cCode">Team</code> and then click Edit. </p><a name="wp83070"> </a><p class="pBody"><b class="cBold">TeamEJB-PlayerEJB Relationship</b></p><a name="wp83071"> </a><p class="pBody">The Multiplicity combo box offers four choices. For this relationship, the Many To Many choice should be selected because a team has many players and a player can belong to more than one team.</p><a name="wp83072"> </a><p class="pBody">The information in the Enterprise Bean A box defines <code class="cCode">TeamEJB</code> side of the relationship. The Field Referencing Bean B combo box displays the relationship field (<code class="cCode">players</code>) in <code class="cCode">TeamEJB</code>. This field corresponds to the relationship access methods in the <code class="cCode">TeamBean.java</code> source code: </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">public abstract Collection getPlayers();public abstract void setPlayers(Collection players);<a name="wp83075"> </a></pre></div><a name="wp83083"> </a><p class="pBody"></p><div align="left"><img src="images/Fig524.gif" height="159" width="404" alt="Edit Relationship Dialog Box of TeamJAR" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p>  <a name="83085"> </a><strong><font >Figure 22-4    Edit Relationship Dialog Box of <code class="cCode">TeamJAR</code></font></strong></p><a name="wp83086"> </a><p class="pBody">The selection of the Field Type combo box is <code class="cCode">java.util.Collection</code>, which matches the <code class="cCode">players</code> type in the access methods. The <code class="cCode">players </code>type is a multi-valued object (<code class="cCode">Collection</code>) because on the <code class="cCode">TeamEJB</code> side of the relationship the multiplicity is many.</p><a name="wp83089"> </a><p class="pBody">The <code class="cCode">TeamEJB-PlayerEJB</code> relationship is bidirectional--each bean has a relationship field that identifies the related bean. If this relationship were unidirectional, then one of the beans would not have a relationship field identifying the other bean. For the bean without the relationship field, the value of the Field Referencing combo box would be <code class="cCode">&lt;none&gt;</code>.</p><a name="wp83090"> </a><p class="pBody"><b class="cBold">LeagueEJB-TeamEJB Relationship</b></p><a name="wp83091"> </a><p class="pBody">In the Edit Relationship dialog box, the Multiplicity choice should be One to Many. This choice indicates that a single league has multiple teams.</p><a name="wp83092"> </a><p class="pBody">For <code class="cCode">LeagueEJB</code>, the relationship field is <code class="cCode">teams</code> and for <code class="cCode">TeamEJB</code> it is <code class="cCode">league</code>. Because <code class="cCode">TeamEJB</code> is on the multiple side of the relationship, the <code class="cCode">teams</code> field is a <code class="cCode">Collection</code>. In contrast, since <code class="cCode">LeagueEJB</code> is on the single side of the relationship, the <code class="cCode">league</code> field is a single-valued object, a <code class="cCode">LocalLeague</code>. The <code class="cCode">TeamBean.java</code> code defines the league relationship field with these access methods:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">public abstract LocalLeague getLeague();public abstract void setLeague(LocalLeague league);<a name="wp83093"> </a></pre></div><a name="wp83094"> </a><p class="pBody">For <code class="cCode">TeamEJB</code> (Enterprise Bean B), the Delete When Bean A Is Deleted checkbox is selected. Because of this selection, when a <code class="cCode">LeagueEJB</code> instance is deleted the related <code class="cCode">TeamEJB</code> instances are automatically deleted. This type of deletion, in which one deletion triggers another, is called a <span style="font-style: italic">cascade delete</span>. For <code class="cCode">LeagueEJB</code>, the corresponding checkbox is disabled: If you delete a team, you don't want to automatically delete the league, because there may be other teams in that league. In general, if a bean is on the multiple side of a relationship, the other bean cannot be automatically deleted.</p><a name="wp83096"> </a><h4 class="pHeading3">PlayerEJB</h4><a name="wp83097"> </a><p class="pBody">In the tree view, expand the <code class="cCode">TeamJAR</code> node and select the <code class="cCode">PlayerEJB</code> entity bean.</p><a name="wp83099"> </a><h5 class="pHeading4">General Tab (PlayerEJB)</h5><a name="wp83100"> </a><p class="pBody">This tab shows the enterprise bean class and interfaces. Since the <code class="cCode">PlayerEJB</code> entity bean uses container-managed persistence, it has local interfaces. It does not have remote interfaces because it does not allow remote access.</p><a name="wp83102"> </a><h5 class="pHeading4">Entity Tab (PlayerEJB)</h5><a name="wp83105"> </a><p class="pBody">The field at the top of the tabbed page define the bean's persistence type (<a  href="CMP6.html#wp83129">Figure 22-5</a>). For <code class="cCode">PlayerEJB</code>, this type is Container-Managed Persistence, version 2.0. (Because version 1.1 did not support relationships, it is not recommended. These version numbers identify a particular release of the Enterprise JavaBeans Specification, not the J2EE Application Server software.)</p><a name="wp83111"> </a><p class="pBody">The Fields To Be Persisted box lists the persistent and relationship fields defined by the access methods in the <code class="cCode">PlayerBean.java</code> code. The checkboxes for the persistent fields must be selected, but those for the relationship fields must not be selected. The <code class="cCode">PlayerEJB</code> entity bean has one relationship field: <code class="cCode">teams</code>.</p><a name="wp83113"> </a><p class="pBody">The abstract schema name is <code class="cCode">Player</code>, a name that represents the relationships and persistent fields of the <code class="cCode">PlayerEJB</code> entity bean. This abstract name is referenced in the <code class="cCode">PlayerEJB</code> EJB QL queries. For more information on EJB QL, see Chapter&nbsp;<a  href="EJBQL.html#wp79663">24</a><a  href="EJBQL.html#wp80587"></a>.</p><a name="wp83127"> </a><p class="pBody"></p><div align="left"><img src="images/Fig535.gif" height="366" width="344" alt="Entity Tab of PlayerEJB" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p>  <a name="83129"> </a><strong><font >Figure 22-5    Entity Tab of <code class="cCode">PlayerEJB</code></font></strong></p><a name="wp83132"> </a><h5 class="pHeading4">Finder/Select Methods Dialog Box (PlayerEJB)</h5><a name="wp83133"> </a><p class="pBody">To open this dialog box, click Finder/Select Methods on the Entity tab. This dialog box (<a  href="CMP6.html#wp83148">Figure 22-6</a>) enables you to view and edit the EJB QL queries for a bean's finder and select methods. For example, to list the finder methods defined in the <code class="cCode">LocalPlayerHome</code> interface, select the Local Finders radio button. When you select the finder method, its EJB QL query appears in an editable text field.</p><a name="wp83146"> </a><p class="pBody"></p><div align="left"><img src="images/Fig546.gif" height="200" width="374" alt="Finder-Select Methods Dialog Box of PlayerEJB" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p>  <a name="83148"> </a><strong><font >Figure 22-6    Finder/Select Methods Dialog Box of <code class="cCode">PlayerEJB</code></font></strong></p><a name="wp83150"> </a><h5 class="pHeading4">Sun-Specific CMP Settings Dialog Box (PlayerEJB)</h5><a name="wp83151"> </a><p class="pBody">To view this dialog box, click Sun-specific CMP Settings in the Entity tab. In this dialog box, you define the runtime settings of an entity bean with container-managed persistence. These runtime settings are specific to the J2EE Application Server; other implementations of the J2EE platform may take a different approach.</p><a name="wp83158"> </a><p class="pBody">In the J2EE Application Server, the bean's persistent fields are stored in a relational database table. In the checkboxes of the Database Table box, you specify whether or not the server automatically creates or drops the table. If you want to save the data in your table between deployments, then make sure that the Delete Table checkbox is not selected. Otherwise, every time you undeploy the bean, the table will be deleted.</p><a name="wp83161"> </a><p class="pBody">The J2EE server accesses the database by issuing SQL calls. In an entity bean with container-managed persistence, you do not code these calls. The container creates the SQL calls automatically when you access the persistent fields and relationships.</p><a name="wp83162"> </a><p class="pBody">In the Persistent Field Mapping section, the mappings and relationships for all the entity beans in TeamJAR are listed. For example, to see the mappings and relationships for PlayerEJB, select it from the Enterprise Bean field.</p><a name="wp83404"> </a><p class="pBody"></p><div align="left"><img src="images/sunCMPSettings7.gif" height="402" width="434" alt="RosterApp J2EE Application" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p>  <a name="83408"> </a><strong><font >Figure 22-7    CMP Settings for PlayerEJB.</font></strong></p>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="CMP5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="CMP7.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -