blob: 8c5e26066e8e29858e6aabfae9abe28f5025d8b9 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!-- Run date = August 18, 2006 10:55:01 -->
<meta name="OAC_IGNORE_SKIP_NAV" content="true" />
<title>Dali Object-Relational Mapping Tool Advanced Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta name="generator" content="Oracle DARB XHTML Converter - Version 4.5.2 Build 48-Patch" />
<meta name="date" content="2005-07-10T12:57:20+08:00" />
<meta name="robots" content="all" scheme="http://www.robotstxt.org/" />
<meta name="doctitle" content="Dali Object-Relational Mapping Tool Advanced Tutorial" />
<meta name="relnum" content="Release 0.5.0" />
<meta name="partnum" content="" />
<link rel="copyright" href="dcommon/html/cpyr.htm" title="Copyright" type="text/html" />
<link rel="stylesheet" href="dcommon/css/blafdoc.css" title="Oracle BLAFDoc" type="text/css" />
<link rel="start" href="../../index.htm" title="Home" type="text/html" />
</head>
<body>
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td align="left" width="86%">
<h1>Dali Object-Relational Mapping Tool</h1>
</td>
</tr>
</table>
<p><a name="BEGIN" id="BEGIN"></a></p>
<p class="booktitle">Advanced Tutorial</p>
<p><span class="revnumber">Release 0.5.0</span> <span class="platform">&nbsp;</span></p>
<p class="invpartnumber">&nbsp;</p>
<p class="date">August 2006</p>
<p>This tutorial provides information on building and deploying dynamic web application for an order-entry system using Dali. The mapped classes are packaged into a web application, demonstrating one way to deploy JPA applications. This tutorial focuses on using Dali to map your classes to a relational database &ndash; the details of the web application are not discussed in this document.</p>
<p>This tutorial includes:</p>
<ul>
<li type="disc">
<p><a href="#BABEFHCD">Requirements and installation</a></p>
</li>
<li type="disc">
<p><a href="#CIHFJEIF">Dali Advanced Tutorial</a></p>
</li>
</ul>
<p>For additional information, please visit the Dali home page at: <code><a href="http://www.eclipse.org/dali">http://www.eclipse.org/dali</a></code>.</p>
<p><a id="BABEFHCD" name="BABEFHCD"></a></p>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h2>Requirements and installation<a id="sthref1" name="sthref1"></a><a id="sthref2" name="sthref2"></a></h2>
<p>Before building this tutorial, ensure that your environment meets the following <span class="italic">minimum</span> requirements:</p>
<ul>
<li type="disc">
<p>Eclipse 3.2 (<code><a href="http://www.eclipse.org/downloads">http://www.eclipse.org/downloads</a></code>)</p>
</li>
<li type="disc">
<p>Java Runtime Environment (JRE) 1.5 (<code><a href="http://java.com">http://java.com</a></code>)</p>
</li>
<li type="disc">
<p>Eclipse Web Tools Platform (WTP) 1.5 (<code><a href="http://www.eclipse.org/webtools">http://www.eclipse.org/webtools</a></code>)</p>
</li>
<li type="disc">
<p>Java Persistence API (JPA) for Java EE 5. This tutorial uses the TopLink Essentials JPA implementation that can be obtained from:</p>
<pre xml:space="preserve" class="oac_no_warn">
<code><a href="http://otn.oracle.com/jpa">http://otn.oracle.com/jpa</a></code>
</pre></li>
<li type="disc">
<p>Java Server Faces (JSF) 1.1 for Java EE5. The reference implementation can be obtained from:</p>
<pre xml:space="preserve" class="oac_no_warn">
<code><a href="https://javaserverfaces.dev.java.net/">https://javaserverfaces.dev.java.net/</a></code>
</pre>
<div align="center">
<div class="inftblnote"><br />
<table class="Note oac_no_warn" summary="This is a layout table to format a note" title="This is a layout table to format a note" dir="ltr" border="1" width="80%" frame="hsides" rules="groups" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="notep1">Note:</p>
This tutorial requires JSF 1.1. Do not use JSF 1.2.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
</li>
<li type="disc">
<p>J2SE Application server. This tutorial uses Apache Tomcat 5.5 that can be obtained from:</p>
<pre xml:space="preserve" class="oac_no_warn">
<code><a href="http://tomcat.apache.org/">http://tomcat.apache.org/</a></code>
</pre></li>
<li type="disc">
<p>Relational database. This tutorial uses Apace Derby 10.1.3.1 that can be obtained from:</p>
<pre xml:space="preserve" class="oac_no_warn">
<code><a href="http://db.apache.org/derby/">http://db.apache.org/derby/</a></code>
</pre></li>
<li type="disc">
<p>Tutorial source files (including the nonpersistent files, implementation classes, and web content): <code><a href="http://www.eclipse.org/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip">http://www.eclipse.org/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip</a></code>. Unzip these files to your &lt;DALI_TUTORIAL_HOME&gt;. The following table identifies the files in the <code>dali_tutorial_application.zip</code>:</p>
<div class="inftblhruleinformal">
<table class="HRuleInformal" title="This table lists the tutorial files." summary="This table lists the tutorial files." dir="ltr" border="1" width="100%" frame="hsides" rules="rows" cellpadding="3" cellspacing="0">
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t3">File</th>
<th align="left" valign="bottom" id="r1c2-t3">Description</th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t3" headers="r1c1-t3">commons-cli-1.0.jar</td>
<td align="left" headers="r2c1-t3 r1c2-t3">Used to parse the command line arguments when populating the database.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t3" headers="r1c1-t3">Dali_Tutorial_Web.zip</td>
<td align="left" headers="r3c1-t3 r1c2-t3">Java source and web files used for the tutorial dynamic web project.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t3" headers="r1c1-t3">dalimodel.jar</td>
<td align="left" headers="r4c1-t3 r1c2-t3">The completed model project. This is used to create and populate the database and is also included for reference.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r5c1-t3" headers="r1c1-t3">populatedb.bat</td>
<td align="left" headers="r5c1-t3 r1c2-t3">Script to create and populate the tutorial database schema.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r6c1-t3" headers="r1c1-t3">populatedb.jar</td>
<td align="left" headers="r6c1-t3 r1c2-t3">Java source files used to create and populate the database.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblhruleinformal" --></li>
</ul>
<p>Refer to <code><a href="http://www.eclipse.org/dali/gettingstarted_main.html">http://www.eclipse.org/dali/gettingstarted_main.html</a></code> for additional installation information.</p>
</div>
<!-- class="sect1" -->
<p><a id="CIHFJEIF" name="CIHFJEIF"></a></p>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h2>Dali Advanced Tutorial</h2>
<p>In this tutorial, you will create a dynamic web application for an order-entry system. <a href="#CHDEABDB">Figure: Advanced Tutorial Object Model</a> illustrates the object model for this tutorial.</p>
<div class="figure"><a id="CHDEABDB" name="CHDEABDB"></a>
<p class="titleinfigure">Advanced Tutorial Object Model</p>
<img src="img/advanced_object_model.png" alt="This figure shows the object model for the tutorial." title="This figure shows the object model for the tutorial." /><br /></div>
<!-- class="figure" -->
<p>The <span class="bold">Item</span> class represents the items that can be ordered or maintained in inventory. The <span class="bold">Inventory</span> class models items that are in inventory. The <span class="bold">Order</span> class represents a request for delivery of a particular item.</p>
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref3" name="sthref3"></a>
<h3>Generate the tutorial database schema</h3>
<p>The advanced tutorial project uses three database tables to store each order: INVENTORY, ITEM, and ORDER_TABLE.</p>
<div class="tblhruleformal"><a id="sthref4" name="sthref4"></a><a id="CIHFHBAE" name="CIHFHBAE"></a>
<p class="titleintable">Tutorial Database Schema</p>
<table class="HRuleFormal" title="Tutorial Database Schema" summary="This table describes the database tables for the tutorial project." dir="ltr" border="1" width="100%" frame="hsides" rules="rows" cellpadding="3" cellspacing="0">
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t4">Table</th>
<th align="left" valign="bottom" id="r1c2-t4">Column</th>
<th align="left" valign="bottom" id="r1c3-t4">Type</th>
<th align="left" valign="bottom" id="r1c4-t4">Details</th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t4" headers="r1c1-t4" rowspan="5">
<p>INVENTORY</p>
</td>
<td align="left" headers="r2c1-t4 r1c2-t4">
<p>COST</p>
</td>
<td align="left" headers="r2c1-t4 r1c3-t4">
<p>NUMBER(10,4)</p>
</td>
<td align="left" headers="r2c1-t4 r1c4-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t4" headers="r2c1-t4 r1c1-t4">
<p>ITEM_SKU</p>
</td>
<td align="left" headers="r2c1-t4 r3c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r2c1-t4 r3c1-t4 r1c3-t4">
<p>Primary Key, references ITEM.SKU</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t4" headers="r2c1-t4 r1c1-t4">
<p>PRICE</p>
</td>
<td align="left" headers="r2c1-t4 r4c1-t4 r1c2-t4">
<p>NUMBER(10,4)</p>
</td>
<td align="left" headers="r2c1-t4 r4c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r5c1-t4" headers="r2c1-t4 r1c1-t4">
<p>QUANTITY</p>
</td>
<td align="left" headers="r2c1-t4 r5c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r2c1-t4 r5c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r6c1-t4" headers="r2c1-t4 r1c1-t4">
<p>VERSION</p>
</td>
<td align="left" headers="r2c1-t4 r6c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r2c1-t4 r6c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r7c1-t4" headers="r1c1-t4" rowspan="5">
<p>ITEM</p>
</td>
<td align="left" headers="r7c1-t4 r1c2-t4">
<p>CATEGORY</p>
</td>
<td align="left" headers="r7c1-t4 r1c3-t4">
<p>VARCHAR2(255)</p>
</td>
<td align="left" headers="r7c1-t4 r1c4-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r8c1-t4" headers="r7c1-t4 r1c1-t4">
<p>DESCRIPTION</p>
</td>
<td align="left" headers="r7c1-t4 r8c1-t4 r1c2-t4">
<p>VARCHAR2(255)</p>
</td>
<td align="left" headers="r7c1-t4 r8c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r9c1-t4" headers="r7c1-t4 r1c1-t4">
<p>NAME</p>
</td>
<td align="left" headers="r7c1-t4 r9c1-t4 r1c2-t4">
<p>VARCHAR2(255)</p>
</td>
<td align="left" headers="r7c1-t4 r9c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r10c1-t4" headers="r7c1-t4 r1c1-t4">
<p>SKU</p>
</td>
<td align="left" headers="r7c1-t4 r10c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r7c1-t4 r10c1-t4 r1c3-t4">
<p>Primary Key</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r11c1-t4" headers="r7c1-t4 r1c1-t4">
<p>VERSION</p>
</td>
<td align="left" headers="r7c1-t4 r11c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r7c1-t4 r11c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r12c1-t4" headers="r1c1-t4" rowspan="7">
<p>ORDER_TABLE</p>
</td>
<td align="left" headers="r12c1-t4 r1c2-t4">
<p>ARRIVALDATE</p>
</td>
<td align="left" headers="r12c1-t4 r1c3-t4">
<p>DATE</p>
</td>
<td align="left" headers="r12c1-t4 r1c4-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r13c1-t4" headers="r12c1-t4 r1c1-t4">
<p>CURRENTLOCATION</p>
</td>
<td align="left" headers="r12c1-t4 r13c1-t4 r1c2-t4">
<p>VARCHAR2(255)</p>
</td>
<td align="left" headers="r12c1-t4 r13c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r14c1-t4" headers="r12c1-t4 r1c1-t4">
<p>ITEM_SKU</p>
</td>
<td align="left" headers="r12c1-t4 r14c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r12c1-t4 r14c1-t4 r1c3-t4">
<p>Foreign Key, references ITEM.SKU</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r15c1-t4" headers="r12c1-t4 r1c1-t4">
<p>ORDERID</p>
</td>
<td align="left" headers="r12c1-t4 r15c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r12c1-t4 r15c1-t4 r1c3-t4">
<p>Primary Key</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r16c1-t4" headers="r12c1-t4 r1c1-t4">
<p>ORDERINITIATED</p>
</td>
<td align="left" headers="r12c1-t4 r16c1-t4 r1c2-t4">
<p>DATE</p>
</td>
<td align="left" headers="r12c1-t4 r16c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r17c1-t4" headers="r12c1-t4 r1c1-t4">
<p>QUANTITY</p>
</td>
<td align="left" headers="r12c1-t4 r17c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r12c1-t4 r17c1-t4 r1c3-t4"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r18c1-t4" headers="r12c1-t4 r1c1-t4">
<p>VERSION</p>
</td>
<td align="left" headers="r12c1-t4 r18c1-t4 r1c2-t4">
<p>NUMBER(10,0)</p>
</td>
<td align="left" headers="r12c1-t4 r18c1-t4 r1c3-t4"><br /></td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="tblhruleformal" -->
<p>Included in the tutorial source file (<code><a href="http://www.eclipse.org/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip">http://www.eclipse.org/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip</a></code>) are the scripts that will create and populate the tutorial database. By default, the scripts will use the following login information:</p>
<ul>
<li type="disc">
<p><code>driver=org.apache.derby.jdbc.ClientDriver</code></p>
</li>
<li type="disc">
<p><code>url=jdbc:derby://localhost:1527/sample;create=true</code></p>
</li>
<li type="disc">
<p><code>user=dali</code></p>
</li>
<li type="disc">
<p><code>password=dali</code></p>
</li>
</ul>
<ol type="1" start="1">
<li>
<p>Install Apache Derby and start the Derby database, using the Network Server framework.</p>
<p>Refer to the Derby documentation (<code><a href="http://db.apache.org/derby/">http://db.apache.org/derby/</a></code>) for details. Be sure to correctly set your DERBY_INSTALL and classpath variables.</p>
</li>
<li>
<p>Place the <code>toplink-essentials.jar</code> and <code>derbyclient.jar</code> files in the same directory as the <code>populatedb.bat</code> file.</p>
</li>
<li>
<p>Execute the <code>populatedb.bat</code> file to create and populate the tutorial database. The script executes the following command:</p>
<pre xml:space="preserve" class="oac_no_warn">
java -classpath populatedb.jar;dalimodel.jar;commons-cli-1.0.jar;toplink-essentials.jar;derbyclient.jar oracle.toplink.jpa.example.inventory.util.PopulateDatabase
</pre>
<p>To override the default login information, include your JDBC driver JAR and login information:</p>
<pre xml:space="preserve" class="oac_no_warn">
java -classpath createschema.jar;dalimodel.jar;commons-cli-1.0.jar;toplink-essentials.jar;<span class="bold">ojdbc14.jar</span> oracle.toplink.jpa.example.inventory.util.PopulateDatabase <span class="bold">-user scott -password tiger -driver oracle.jdbc.OracleDriver -url jdbc:oracle:thin:@localhost:1521:ORCL</span>
</pre></li>
</ol>
<a id="CIHEICJJ" name="CIHEICJJ"></a>
<div class="sect3"><!-- infolevel="all" infotype="General" -->
<h4>Create a database connection</h4>
<p>After creating and populating the database you will need to create a database connection to use with the tutorial application. An active database connection is required to complete the tutorial application.</p>
<ol type="1" start="1">
<li>
<p>Use the New Connection wizard to create a database connection.</p>
<div class="figure"><a id="CIHJBEIF" name="CIHJBEIF"></a>
<p class="titleinfigure">Creating a Database Connection</p>
<img src="img/derby_db_connection.png" alt="This figure shows the New Connection dialog." title="This figure shows the New Connection dialog." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>You can now display the tutorial database in the Eclipse Database Explorer.</p>
</li>
</ol>
<div class="figure"><a id="sthref5" name="sthref5"></a>
<p class="titleinfigure">Database Explorer</p>
<img src="img/database_explorer_adv.png" alt="This figure shows the Database Explorer." title="This figure shows the Database Explorer." /><br /></div>
<!-- class="figure" --></div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref6" name="sthref6"></a>
<h3>Create a Java project</h3>
<p>To begin the tutorial, you must create a new Eclipse project. This Java project will contain the model classes for the tutorial application.</p>
<ol type="1" start="1">
<li>
<p>Select <span class="gui-object-action">File &gt; New &gt; Project</span>. The New Project dialog appears.</p>
</li>
<li>
<p>On the <span class="gui-object-title">New Project</span> dialog, select <span class="gui-object-action">Java &gt; Java Project</span> and click <span class="gui-object-action">Next</span>. The New Java Project wizard appears.</p>
</li>
<li>
<p>On the New Java Project page, enter the following information and click <span class="bold">Next</span>.</p>
<ul>
<li type="disc">
<p>In the <span class="gui-object-action">Project name</span> field enter <code>Dali_Tutorial_Model</code>.</p>
</li>
<li type="disc">
<p>In the <span class="bold">JRE</span> area, select an installed JRE 1.5 (or higher).</p>
</li>
</ul>
</li>
</ol>
<p>Eclipse adds the project to the workbench and opens the Java perspective.</p>
<div class="figure"><a id="sthref7" name="sthref7"></a>
<p class="titleinfigure">New Java Project</p>
<img src="img/new_project.png" alt="Project Explorer with new Java project." title="Project Explorer with new Java project." /><br /></div>
<!-- class="figure" -->
<p>Now, add persistence to the project:</p>
<ol type="1" start="1">
<li>
<p>Right-click the project in the Explorer and select <span class="gui-object-action">Java Persistence &gt; Add Java Persistence</span>. The Add Persistence dialog appears.</p>
<div class="figure"><a id="CIHEBFJF" name="CIHEBFJF"></a>
<p class="titleinfigure">Add Java Persistence Dialog</p>
<img src="img/add_persistence_dialog.png" alt="This figure shows the Add Java Persistence dialog." title="This figure shows the Add Java Persistence dialog." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>On the Add Persistence dialog select the database connection you created in the <a href="#CIHEICJJ">"Create a database connection"</a> section.</p>
<div align="center">
<div class="inftblnote"><br />
<table class="Note oac_no_warn" summary="This is a layout table to format a note" title="This is a layout table to format a note" dir="ltr" border="1" width="80%" frame="hsides" rules="groups" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="notep1">Note:</p>
You must be connected to the database before adding persistence to the project.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
</li>
<li>
<p>Click <span class="gui-object-action">Configure the project build path</span> to add the library or JARs that contain the Java Persistence API (JPA) and entities to the project's <span class="gui-object-title">Java Build Path</span>. For this tutorial, use the <code>toplink-essentials.jar</code>.</p>
</li>
<li>
<p>In the <span class="bold">Packaging Settings</span> area, enter the following information and click <span class="bold">Finish</span>:</p>
<ul>
<li type="disc">
<p>Persistence version &ndash; <code>1.0</code></p>
</li>
<li type="disc">
<p>Persistence unit name &ndash; Unique name of the persistence unit. For this tutorial, use <code>default</code>.</p>
</li>
</ul>
</li>
</ol>
<p>Eclipse adds the persistence information to the project.</p>
<div class="figure"><a id="sthref8" name="sthref8"></a>
<p class="titleinfigure">Java Project with Persistence</p>
<img src="img/new_project_2.png" alt="The Window &gt; Open Perspective &gt; Other option." title="The Window &gt; Open Perspective &gt; Other option." /><br /></div>
<!-- class="figure" -->
<p>You can now work in the <span class="gui-object-title">Persistence perspective</span> to begin working with Java persistence entities.</p>
<ol type="1" start="1">
<li>
<p>Select <span class="gui-object-action">Window &gt; Open Perspective &gt; Other</span>. The <a href="#CIHHHBHB">Select Perspective Dialog</a> appears.</p>
<div class="figure"><a id="sthref9" name="sthref9"></a>
<p class="titleinfigure">Selecting Persistence Perspective</p>
<img src="img/open_perspective.png" alt="The Window &gt; Open Perspective &gt; Other option." title="The Window &gt; Open Perspective &gt; Other option." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>On the Select <span class="gui-object-title">Perspective</span> dialog, select <span class="gui-object-action">Java Persistence</span> and click <span class="gui-object-action">OK</span>. The workbench adds the <span class="gui-object-title">Persistence Outline</span> and <span class="gui-object-title">Persistence Properties</span> views.</p>
<div class="figure"><a id="CIHHHBHB" name="CIHHHBHB"></a>
<p class="titleinfigure">Select Perspective Dialog</p>
<img src="img/select_perspective.png" alt="The Select Perspective dialog with the Perspective option." title="The Select Perspective dialog with the Perspective option." /><br /></div>
<!-- class="figure" --></li>
</ol>
</div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref10" name="sthref10"></a>
<h3>Create persistent Java entities</h3>
<p>The <a href="#CHDEABDB">Advanced Tutorial Object Model</a> contains three entities: <span class="bold">Inventory</span>, <span class="bold">Item</span>, and <span class="bold">Order</span>. Use this procedure to add the entities to the project.</p>
<ol type="1" start="1">
<li>
<p>Right-click the project in the <span class="gui-object-title">Package Explorer</span> and select <span class="gui-object-action">New &gt; Other</span>. The Select a Wizard dialog appears.</p>
</li>
<li>
<p>In the <span class="gui-object-title">Select a Wizard</span> dialog, select <span class="gui-object-action">Java Persistence &gt; Entity</span> and click <span class="gui-object-action">Next</span>. The Java Class page of the Create New Java Persistence Entity wizard appears.</p>
</li>
<li>
<p>On the <span class="gui-object-title">Java Class</span> page, enter a package name and class name and click <span class="gui-object-action">Finish</span>. For this tutorial, use <code>org.eclipse.dali.example.jsf.inventory.model</code> as package and <code>Inventory</code> as the class name.</p>
</li>
</ol>
<p>Eclipse adds the <span class="bold">Inventory</span> entity to the Package Explorer and adds the <code>@Entity</code> annotation to the class. Repeat this procedure to add the <span class="bold">Item</span> and <span class="bold">Order</span> entities.</p>
<p>Notice that the Problems view reports several errors for each entity. We'll address these shortly.</p>
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref11" name="sthref11"></a>
<h4>Build the entities</h4>
<p>Before mapping the entities to the database, you must add the necessary fields to each entity.</p>
<ol type="1" start="1">
<li>
<p>Add the following fields to the <span class="bold">Inventory</span> entity:</p>
<pre xml:space="preserve" class="oac_no_warn">
protected double cost;
private long id;
protected Item item;
protected double price;
protected int quantity;
protected int version;
</pre>
<p>Add <code>get()</code> and <code>set()</code> methods for the following:</p>
<ul>
<li type="disc">
<p>cost</p>
</li>
<li type="disc">
<p>id</p>
</li>
<li type="disc">
<p>item</p>
</li>
<li type="disc">
<p>price</p>
</li>
<li type="disc">
<p>quantity</p>
</li>
</ul>
</li>
<li>
<p>Add the following fields to the <span class="bold">Item</span> entity:</p>
<pre xml:space="preserve" class="oac_no_warn">
protected String category;
protected String description;
protected String name;
protected long SKU;
protected int version;
</pre>
<p>Add <code>get()</code> and <code>set()</code> methods for the following:</p>
<ul>
<li type="disc">
<p>category</p>
</li>
<li type="disc">
<p>description</p>
</li>
<li type="disc">
<p>name</p>
</li>
<li type="disc">
<p>SKU</p>
</li>
<li type="disc">
<p>version</p>
</li>
</ul>
</li>
<li>
<p>Add the following fields to the <span class="bold">Order</span> entity:</p>
<pre xml:space="preserve" class="oac_no_warn">
protected Date arrivalDate;
protected String currentLocation;
protected Item item;
protected long orderId;
protected Date orderInitiated;
protected int quantity;
protected int version;
</pre>
<p>Import <code>java.sql.Date</code>.</p>
<div align="center">
<div class="inftblnote"><br />
<table class="Note oac_no_warn" summary="This is a layout table to format a note" title="This is a layout table to format a note" dir="ltr" border="1" width="80%" frame="hsides" rules="groups" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="notep1">Note:</p>
Do not use <code>java.util.Date</code>.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<p>Add <code>get()</code> and <code>set()</code> methods for the following:</p>
<ul>
<li type="disc">
<p>arrivalDate</p>
</li>
<li type="disc">
<p>currentLocation</p>
</li>
<li type="disc">
<p>item</p>
</li>
<li type="disc">
<p>orderId</p>
</li>
<li type="disc">
<p>orderInitiated</p>
</li>
<li type="disc">
<p>quantity</p>
</li>
</ul>
</li>
</ol>
</div>
<!-- class="sect3" -->
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref12" name="sthref12"></a>
<h4>Associate the entity with a database table</h4>
<p>Now you must associate each entity with its primary database table.</p>
<ol type="1" start="1">
<li>
<p>In the Package Explorer view, open <span class="bold">Inventory.java</span>.</p>
</li>
<li>
<p>In the <span class="gui-object-title">Persistence Properties</span> view, select <span class="bold">General</span> tab.</p>
</li>
<li>
<p>On the General tab, notice that Dali has automatically identified the default table, <span class="bold">Inventory</span>, associated with the entity.</p>
<div class="figure"><a id="sthref13" name="sthref13"></a>
<p class="titleinfigure">Persistence Properties View for the Inventory Entity</p>
<img src="img/persistence_view_inventory.png" alt="Persistence Properties view for the Inventory entity." title="Persistence Properties view for the Inventory entity." /><br /></div>
<!-- class="figure" --></li>
</ol>
<p>By default, entities are associated with a similarly named database table and Dali identifies these defaults. Like the Inventory entity, even though you have not explicitly associated the <span class="bold">Item</span> entity with a database table, there is no error in the Problems view because the entity name, Item, is identical to the table name (Item).</p>
<p>For the <span class="bold">Order</span> entity, however, there is an error: "The table Order cannot be found on the database." This is because the entity name (Order) is different than the database table (ORDER_TABLE). You must explicitly associate the entity with the ORDER_TABLE table. Dali adds the <code>@Table(name="ORDER_TABLE")</code> annotation to the entity.</p>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref14" name="sthref14"></a>
<h3>Create OR mappings</h3>
<p>Now you're ready to map the attributes of each persistent entity to columns in the appropriate database table. For the tutorial application, you will use the following mapping types:</p>
<ul>
<li type="disc">
<p>ID mappings</p>
</li>
<li type="disc">
<p>Basic mappings</p>
</li>
<li type="disc">
<p>One-to-one mappings</p>
</li>
<li type="disc">
<p>One-to-many mappings</p>
</li>
<li type="disc">
<p>Version mappings</p>
</li>
</ul>
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref15" name="sthref15"></a>
<h4>Create ID mappings</h4>
<p>Use an <span class="bold">ID Mapping</span> to specify the primary key of an entity. Each persistent entity must have an ID. Notice that the Problems view reports "Entity does not have an Id" for each entity.</p>
<ol type="1" start="1">
<li>
<p>In the Package Explorer view, open <span class="bold">Inventory.java</span>.</p>
</li>
<li>
<p>Expand the <span class="bold">Inventory</span> entity in the <span class="gui-object-title">Persistence Outline view</span> and select the <span class="bold">id</span> field. The Persistence Properties view displays the properties for the field.</p>
</li>
<li>
<p>In the <span class="gui-object-title">Map As</span> field, select <span class="gui-object-action">ID</span>.</p>
<div class="figure"><a id="CIHIEIHJ" name="CIHIEIHJ"></a>
<p class="titleinfigure">ID Mapping for id Field</p>
<img src="img/persistence_view_id.png" alt="General tab of Persistence Properties page." title="General tab of Persistence Properties page." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>Use this table to complete the remaining fields on the General tab in the <span class="gui-object-title">Persistence Properties</span> view.</p>
<div class="inftblruleinformal">
<table class="RuleInformal" title="This table lists the fields in the Persistence Properties view for this mapping." summary="This table lists the fields in the Persistence Properties view for this mapping." dir="ltr" border="1" width="100%" frame="border" rules="all" cellpadding="3" cellspacing="0">
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t7">Property</th>
<th align="left" valign="bottom" id="r1c2-t7">Description</th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t7" headers="r1c1-t7">Map As</td>
<td align="left" headers="r2c1-t7 r1c2-t7">Defines this mapping as an <span class="bold">ID Mapping</span>. Dali adds the <code>@Id</code> annotation to the entity.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t7" headers="r1c1-t7">Column</td>
<td align="left" headers="r3c1-t7 r1c2-t7">The database column for the primary key of the table associated with the entity. Select <span class="bold">ITEM_SKU</span>.
<p>Because the database column (ITEM_SKU) is named differently than the entity field (id), Dali adds the <code>@Column(name="ITEM_SKU"</code>) annotation.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t7" headers="r1c1-t7">Insertable, Updatable</td>
<td align="left" headers="r4c1-t7 r1c2-t7">Select <span class="bold">False</span> for both fields to ensure that this value is never overwritten in the database.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblruleinformal" --></li>
</ol>
<p>In the Persistence Outline, the <span class="bold">id</span> field is identified as the primary key by the following icon:</p>
<div class="figure"><a id="sthref16" name="sthref16"></a>
<p class="titleinfigure">Persistence Outline for Inventory Entity</p>
<img src="img/persistence_outline_inventory_id.png" alt="Persistence Outline view showing id field." title="Persistence Outline view showing id field." /><br /></div>
<!-- class="figure" -->
<p>Repeat this procedure to map the following primary keys (as shown in <a href="#CIHFHBAE">Table: Tutorial Database Schema</a>):</p>
<ul>
<li type="disc">
<p>The <span class="bold">SKU</span> field of the <span class="bold">Item</span> entity to the SKU column of the ITEM table.</p>
</li>
<li type="disc">
<p>The <span class="bold">orderId</span> field of the <span class="bold">Order</span> entity to the ORDERID column of the ORDER_TABLE table.</p>
</li>
</ul>
<p>For both of these mappings:</p>
<ol type="1" start="1">
<li>
<p>Leave the <span class="bold">Insertable</span> and <span class="bold">Updatable</span> fields on the <span class="gui-object-title">General</span> tab (see <a href="#CIHIEIHJ">Figure: ID Mapping for id Field</a>) as their default values.</p>
</li>
<li>
<p>Click the <span class="bold">PK Generation</span> tab.</p>
<div class="figure"><a id="sthref17" name="sthref17"></a>
<p class="titleinfigure">Primary Key Generation for id Field</p>
<img src="img/persistence_view_empid_pk.png" alt="PK Generation tab of the Persistence Properties page." title="PK Generation tab of the Persistence Properties page." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>Select the <span class="gui-object-action">Primary Key Generation</span> option.</p>
</li>
<li>
<p>Use this table to complete the remaining fields on the PK Generation tab in the <span class="gui-object-title">Persistence Properties</span> view.</p>
<div class="inftblruleinformal">
<table class="RuleInformal" title="This table lists the fields in the Persistence Properties view for this mapping." summary="This table lists the fields in the Persistence Properties view for this mapping." dir="ltr" border="1" width="100%" frame="border" rules="all" cellpadding="3" cellspacing="0">
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t8">Property</th>
<th align="left" valign="bottom" id="r1c2-t8">Description</th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t8" headers="r1c1-t8">Generated Value</td>
<td align="left" headers="r2c1-t8 r1c2-t8">These fields define how the primary key is generated. Dali adds the <code>@GeneratedValue</code> annotation to the entity.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t8" headers="r1c1-t8">&nbsp;&nbsp;Strategy</td>
<td align="left" headers="r3c1-t8 r1c2-t8">For the tutorial project, use the <span class="bold">Auto</span> option.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t8" headers="r1c1-t8">&nbsp;&nbsp;Generator&nbsp;Name</td>
<td align="left" headers="r4c1-t8 r1c2-t8">Leave this field blank.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblruleinformal" --></li>
</ol>
</div>
<!-- class="sect3" -->
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref18" name="sthref18"></a>
<h4>Create basic mappings</h4>
<p>Use a <span class="bold">Basic Mapping</span> to map an attribute directly to a database column. In the object model, the <span class="bold">quantity</span> field of the <span class="bold">Inventory</span> class maps directly to the QUANTITY column of the INVENTORY database table.</p>
<ol type="1" start="1">
<li>
<p>In the Package Explorer view, open <span class="bold">Inventory.java</span>.</p>
</li>
<li>
<p>In the Persistence Outline view, select the <span class="bold">quantity</span> field of the <span class="bold">Inventory</span> entity. The Persistence Properties view displays the properties for the field.</p>
<p>Notice that Dali has already identified the mapping as the Basic mapping type. By default, all attributes use Basic mapping.</p>
</li>
<li>
<div class="figure"><a id="sthref19" name="sthref19"></a>
<p class="titleinfigure">Basic Mapping for quantity</p>
<img src="img/persistence_view_quantity.png" alt="Basic mapping in the Persistence Properties page." title="Basic mapping in the Persistence Properties page." /><br /></div>
<!-- class="figure" --></li>
</ol>
<p>Notice that Dali has automatically identified the QUANTITY field and INVENTORY table for this mapping. Dali identifies the defaults for the mapping.</p>
<p>In the Persistence Outline, the <span class="bold">quantity</span> field is identified as a basic mapping as shown in the following figure:</p>
<div class="figure"><a id="sthref20" name="sthref20"></a>
<p class="titleinfigure">Persistence Outline for Inventory Entity</p>
<img src="img/persistence_outline_inventory_quantity.png" alt="Quantity attribute in the Persistence Outline view." title="Quantity attribute in the Persistence Outline view." /><br /></div>
<!-- class="figure" -->
<p>Repeat this procedure to review each of the following <span class="bold">Basic</span> mappings:</p>
<ul>
<li type="disc">
<p><span class="bold">Item</span> entity</p>
<ul>
<li type="circle">
<p><span class="bold">description</span> field to DESCRIPTION column</p>
</li>
<li type="circle">
<p><span class="bold">name</span> field to NAME column</p>
</li>
<li type="circle">
<p><span class="bold">category</span> field to CATEGORY column</p>
</li>
</ul>
</li>
<li type="disc">
<p><span class="bold">Order</span> Entity</p>
<ul>
<li type="circle">
<p><span class="bold">orderInitiated</span> field to ORDERINITIATED column</p>
</li>
<li type="circle">
<p><span class="bold">arrivalDate</span> field to ARRIVALDATE column</p>
</li>
<li type="circle">
<p><span class="bold">currentLocation</span> field to CUURENTLOCATION column</p>
</li>
<li type="circle">
<p><span class="bold">quantity</span> field to QUANTITY column</p>
</li>
</ul>
</li>
<li type="disc">
<p><span class="bold">Inventory</span> Entity</p>
<ul>
<li type="circle">
<p><span class="bold">cost</span> field to COST column</p>
</li>
<li type="circle">
<p><span class="bold">price</span> field to PRICE column</p>
</li>
</ul>
</li>
</ul>
</div>
<!-- class="sect3" -->
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref21" name="sthref21"></a>
<h4>Create one-to-one mappings</h4>
<p>Use a <span class="bold">One-to-One Mapping</span> to define a relationship from an attribute to another class, with one-to-one multiplicity to a database column. In the object model, the <span class="bold">item</span> field of the <span class="bold">Inventory</span> class has a one-to-one relationship to the <span class="bold">Item</span> class; each inventory object contains a single item.</p>
<ol type="1" start="1">
<li>
<p>In the Package Explorer view, open <span class="bold">Inventory.java</span>.</p>
</li>
<li>
<p>In the Persistence Outline view, select the <span class="bold">item</span> field of the <span class="bold">Inventory</span> entity. The Persistence Properties view displays the properties for the field.</p>
</li>
<li>
<p>In the <span class="gui-object-title">Map As</span> field, select <span class="gui-object-action">One-to-One</span>.</p>
<div class="figure"><a id="sthref22" name="sthref22"></a>
<p class="titleinfigure">One-to-one Mapping for item</p>
<img src="img/persistence_view_inventory_11.png" alt="General tab in the Persistence Properties page." title="General tab in the Persistence Properties page." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>Dali has identified the default Target Entity for the mapping: org.eclipse.dali.example.jsf.inventory.model.Item.class.</p>
<p>Leave the other fields with their default values.</p>
</li>
</ol>
<p>In the Persistence Outline, the <span class="bold">item</span> field is identified as a one-to-one mapping, as shown in the following figure:</p>
<div class="figure"><a id="sthref23" name="sthref23"></a>
<p class="titleinfigure">Persistence Outline for Inventory Entity</p>
<img src="img/persistence_outline_inventory_item.png" alt="Item attribute iin the Persistence Outline view." title="Item attribute iin the Persistence Outline view." /><br /></div>
<!-- class="figure" -->
<p>Repeat this procedure to create the following additional one-to-one mapping:</p>
<ul>
<li type="disc">
<p>Create a one-to-one mapping from the <span class="bold">item</span> attribute of the <span class="bold">Order</span> entity to the <span class="bold">Item</span>.</p>
</li>
</ul>
</div>
<!-- class="sect3" -->
<a id="CIHFGJGH" name="CIHFGJGH"></a>
<div class="sect3"><!-- infolevel="all" infotype="General" -->
<h4>Create version mappings</h4>
<p>Use a <span class="bold">Version Mapping</span> to specify the database field used by a persistent entity for optimistic locking.</p>
<ol type="1" start="1">
<li>
<p>In the Package Explorer view, open <span class="bold">Inventory.java</span>.</p>
</li>
<li>
<p>In the Persistence Outline view, select the <span class="bold">version</span> field of the <span class="bold">Inventory</span> entity. The Persistence Properties view displays the properties for the field.</p>
</li>
<li>
<p>In the <span class="gui-object-title">Map As</span> field, select <span class="gui-object-action">Version</span>.</p>
<div class="figure"><a id="sthref24" name="sthref24"></a>
<p class="titleinfigure">Version Mapping for version</p>
<img src="img/persistence_view_item_version.png" alt="Verion mapping in the Persistence Properties page." title="Verion mapping in the Persistence Properties page." /><br /></div>
<!-- class="figure" --></li>
</ol>
<p>Notice that Dali has identified the default column in the INVENTORY database table. In the Persistence Outline, the <span class="bold">Version</span> field is identified as a version mapping, as shown in the following figure:</p>
<div class="figure"><a id="sthref25" name="sthref25"></a>
<p class="titleinfigure">Persistence Outline for Inventory Entity</p>
<img src="img/persistence_outline_inventory_version.png" alt="Version attribute of the Inventory entity." title="Version attribute of the Inventory entity." /><br /></div>
<!-- class="figure" -->
<p>Repeat this procedure to create following version mappings:</p>
<ul>
<li type="disc">
<p><span class="bold">version</span> attribute of the <span class="bold">Order</span> entity</p>
</li>
<li type="disc">
<p><span class="bold">version</span> attribute of the <span class="bold">Item</span> entity</p>
</li>
</ul>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref26" name="sthref26"></a>
<h3>Add the queries</h3>
<p>You must define the following named queries in the <span class="bold">Inventory</span> and <span class="bold">Order</span> entities:</p>
<ul>
<li type="disc">
<p><code>inventoryForCategory</code></p>
</li>
<li type="disc">
<p><code>shippedOrdersForItem</code></p>
</li>
<li type="disc">
<p><code>pendingOrdersForItem</code></p>
</li>
</ul>
<p>The tutorial source files include the <code>EntityManager</code> that will execute the queries at runtime.</p>
<ol type="1" start="1">
<li>
<p>Add the following query to the <span class="bold">Inventory</span> entity.</p>
<pre xml:space="preserve" class="oac_no_warn">
import javax.persistence.NamedQuery;
@NamedQuery(name="inventoryForCategory", query="SELECT i FROM Inventory i WHERE i.item.category = :category and i.quantity &lt;= :maxQuantity")
</pre></li>
<li>
<p>Add the following queries to the <span class="bold">Order</span> entity.</p>
<pre xml:space="preserve" class="oac_no_warn">
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@NamedQueries({
@NamedQuery(name="shippedOrdersForItem", query="SELECT o FROM Order o JOIN o.item i WHERE i.sKU = :itemId and o.arrivalDate is not null"),
@NamedQuery(name="pendingOrdersForItem", query="SELECT o FROM Order o WHERE o.item.sKU = :itemId and o.arrivalDate is null")
})
</pre></li>
</ol>
</div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref27" name="sthref27"></a>
<h3>Manage the persistence.xml file</h3>
<p>When you originally added persistence to the project on the Add Persistence dialog, you selected to create the <code>persistence.xml</code>. Dali created a basic file, containing the persistence unit and provider information.</p>
<p>Use this procedure to add the entities to the <code>persistence.xml</code> file.</p>
<ol type="1" start="1">
<li>
<p>Right-click the <code>persistence.xml</code> file in the <span class="gui-object-title">Package Explorer</span> and select <span class="gui-object-action">Java Persistence &gt; Synchronize Classes</span>.</p>
<div class="figure"><a id="sthref28" name="sthref28"></a>
<p class="titleinfigure">Synchronizing the persistence.xml File</p>
<img src="img/synchornize_classes_jsf.png" alt="Java Persistence &gt; Synchronize Classes option." title="Java Persistence &gt; Synchronize Classes option." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>Dali adds the necessary <code>&lt;class&gt;</code> elements to the <code>persistence.xml</code> file:</p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;class&gt;org.eclipse.dali.example.jsf.inventory.model.Inventory&lt;/class&gt;
&lt;class&gt;org.eclipse.dali.example.jsf.inventory.model.Item&lt;/class&gt;
&lt;class&gt;org.eclipse.dali.example.jsf.inventory.model.Order&lt;/class&gt;
</pre></li>
<li>
<p>Add your database-specific login information to the <code>persistence.xml</code> file. For example:</p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;properties&gt;
&lt;property name="toplink.logging.level" value="FINEST"/&gt;
&lt;property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/&gt;
&lt;property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/sample;create=true"/&gt;
&lt;property name="toplink.jdbc.user" value="dali"/&gt;
&lt;property name="toplink.jdbc.password" value="dali"/&gt;
&lt;/properties&gt;
</pre>
<p>This information should be identical to the values that you used when creating the database connection (see <a href="#CIHJBEIF">Figure: Creating a Database Connection</a>).</p>
</li>
<li>
<p>Save the <code>persistence.xml</code> file.</p>
</li>
</ol>
</div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref29" name="sthref29"></a>
<h3>Create the dynamic web project</h3>
<p>To complete the tutorial, you must create a web project. This web project will contain the business logic and presentation files for the tutorial application.</p>
<ol type="1" start="1">
<li>
<p>Select <span class="gui-object-action">File &gt; New &gt; Project</span>. The New Project dialog appears.</p>
</li>
<li>
<p>On the <span class="gui-object-title">New Project</span> dialog, select <span class="gui-object-action">Web &gt; Dynamic Web Project</span> and click <span class="gui-object-action">Next</span>. The New Dynamic Web Project wizard appears.</p>
</li>
<li>
<p>On the <span class="gui-object-title">Dynamic Web Project</span> page, enter the following information and click <span class="bold">Next</span>:</p>
<ul>
<li type="disc">
<p>In the <span class="gui-object-action">Project name</span> field enter <code>Dali_Tutorial_Application</code>.</p>
</li>
<li type="disc">
<p>In the <span class="bold">Target Runtime</span> field, select your web server configuration (for this tutorial, select <span class="bold">Apache Tomcat v5.5</span>), or click <span class="bold">New</span> to create a new configuration.</p>
</li>
<li type="disc">
<p>In the Configurations field, select <span class="bold">Custom</span>.</p>
</li>
</ul>
<div class="figure"><a id="sthref30" name="sthref30"></a>
<p class="titleinfigure">Dynamic Web Project Page of the New Dynamic Web Project Wizard</p>
<img src="img/dynamic_web_project_dialog.png" alt="This figure shows the Dynamic Web Project dialog." title="This figure shows the Dynamic Web Project dialog." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>On the Project Facets page, verify that the Java facet uses version <span class="bold">5.0</span> and click <span class="bold">Finish</span>.</p>
<div class="figure"><a id="sthref31" name="sthref31"></a>
<p class="titleinfigure">Project Facets Page</p>
<img src="img/project_facets_dialog.png" alt="This figure shows the Project Facets page of the wizard." title="This figure shows the Project Facets page of the wizard." /><br /></div>
<!-- class="figure" --></li>
</ol>
<p>Eclipse creates an new web project.</p>
<div class="figure"><a id="sthref32" name="sthref32"></a>
<p class="titleinfigure">New Web Project</p>
<img src="img/new_web_project.png" alt="Project Explorer with new Java project." title="Project Explorer with new Java project." /><br /></div>
<!-- class="figure" -->
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref33" name="sthref33"></a>
<h4>Add resources</h4>
<p>Add the following resources to the <span class="bold">Dali_Tutorial_Application</span> project's <code>WebContent/WEB-INF/lib</code> directory:</p>
<ul>
<li type="disc">
<p>JPA JARs (for this tutorial, use <code>toplink-essentials.jar</code> from the TopLink Essentials JPA)</p>
</li>
<li type="disc">
<p>JSF JARs (for this tutorial, use the <code>jsf-api.jar</code> and <code>jsf-impl.jar</code> files from the JSF 1.1 library)</p>
</li>
<li type="disc">
<p>Database JDBC JAR (for this tutorial, use <code>derbyclient.jar</code>)</p>
</li>
</ul>
</div>
<!-- class="sect3" -->
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref34" name="sthref34"></a>
<h4>Associate the model project</h4>
<p>Use this procedure to associate the <span class="bold">Dali_Tutorial_Model</span> project with the <span class="bold">Dali_Tutorial_Application</span> project.</p>
<ol type="1" start="1">
<li>
<p>Right-click the <span class="bold">Dali_Tutorial_Application</span> project in the Explorer and select <span class="gui-object-action">Properties</span>.</p>
</li>
<li>
<p>Click <span class="bold">J2EE Module Dependencies</span>, select the <span class="bold">Dali_Tutorial_Model</span> project, and click <span class="bold">OK</span>.</p>
<div class="figure"><a id="sthref35" name="sthref35"></a>
<p class="titleinfigure">Project Build Path</p>
<img src="img/j2ee_dependencies.png" alt="This figure shows the Projects tab.." title="This figure shows the Projects tab.." /><br /></div>
<!-- class="figure" --></li>
</ol>
</div>
<!-- class="sect3" -->
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref36" name="sthref36"></a>
<h4>Add the project files</h4>
<p>The <span class="bold">Dali_Tutorial_Web.zip</span> (included with <code><a href="http://www.eclipse.org/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip">http://www.eclipse.org/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip</a></code>) file contains the non-entity source files and web content files for the dynamic web project. Unzip the <span class="bold">Dali_Tutorial_Web.zip</span> file into your <span class="bold">Dali_Tutorial_Application</span> project's directory.</p>
<div class="figure"><a id="sthref37" name="sthref37"></a>
<p class="titleinfigure">Dali_Tutorial_Application.zip Project</p>
<img src="img/project_files.png" alt="This figure shows the Dali_Tutorial_Application project." title="This figure shows the Dali_Tutorial_Application project." /><br /></div>
<!-- class="figure" --></div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref38" name="sthref38"></a>
<h3>Deploy the application</h3>
<p>You are now ready to deploy the tutorial application to your server.</p>
<ol type="1" start="1">
<li>
<p>Right-click the <span class="bold">Dali_Tutorial_Application</span> project in the Explorer and select <span class="gui-object-action">Run As &gt; Run on Server</span>. The Run on Server dialog appears.</p>
<p>If you have not yet defined a server, the Define a New Server dialog of the Run On Server wizard appears. Use this wizard to define a new server. For this tutorial, create a Tomcat v5.5 server.</p>
</li>
<li>
<p>Select the <span class="bold">Choose an existing server</span> option, select your sever, and click <span class="bold">Finish</span>.</p>
<ul>
<li type="disc">
<p>The Server view shows the status of your sever and the tutorial application.</p>
</li>
<li type="disc">
<p>The Console view shows the status of the compilation, build, and deployment.</p>
</li>
</ul>
</li>
<li>
<p>A new view opens, displaying the web page for the tutorial application.</p>
<div class="figure"><a id="sthref39" name="sthref39"></a>
<p class="titleinfigure">Tutorial Application</p>
<img src="img/application-index.png" alt="This figure shows the order-entry application." title="This figure shows the order-entry application." /><br /></div>
<!-- class="figure" --></li>
</ol>
</div>
<!-- class="sect2" --></div>
<!-- class="sect1" -->
<p><a id="sthref40" name="sthref40"></a></p>
<hr />
<p>Dali Object-Relational Mapping Tool Advanced Tutorial</p>
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at <code><a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a></code>. For purposes of the EPL, "Program" will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise indicated below, the terms and conditions of the EPL still apply to any source code in the Content.</p>
</body>
</html>