blob: 1211eab520480fb1556b1899e58c3f2a2f3d3e1a [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 = June 5, 2007 13:20:59 -->
<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.3 Build 02" />
<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 1.0.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 1.0.0</span> <span class="platform">&nbsp;</span></p>
<p class="invpartnumber">&nbsp;</p>
<p class="date">June 2007</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/webtools/dali/main.php">http://www.eclipse.org/webtools/dali/main.php</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 requirements:</p>
<ul>
<li type="disc">
<p>Eclipse 3.3 (<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) 2.0 (<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 Apache 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/webtools/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip">http://www.eclipse.org/webtools/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>
<tr align="left" valign="top">
<td align="left" id="r7c1-t3" headers="r1c1-t3">sources.zip</td>
<td align="left" headers="r7c1-t3 r1c2-t3">Java source for the domain model classes that will be used in this tutorial.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblhruleinformal" --></li>
</ul>
<p>Refer to <code><a href="http://www.eclipse.org/webtools/dali/gettingstarted_main.html">http://www.eclipse.org/webtools/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="The object model for the tutorial." title="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/webtools/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip">http://www.eclipse.org/webtools/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. For example:</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>In Eclipse, use the New Connection wizard to create a database connection. Refer to "Creating a Connection Profile" in the Eclispe online help for more information.</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>
Use the SQL Model-JDBC Connection profile to create the connection.</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<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="New Connection dialog." title="New Connection dialog." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>Open the Data Source Explorer view to display the tutorial database.</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">JPA &gt; JPA Project</span> and click <span class="gui-object-action">Next</span>. The New JPA Project wizard appears.</p>
</li>
<li>
<p>On the New JPA 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">Target Runtime</span> area, select <span class="bold">Apache Tomcat</span>.</p>
<p>If you do not have a defined Apache Tomcat target runtime, you must create one. Refer to "Defining the installed server runtime environments" in Web Application Development User Guide for details.</p>
</li>
<li type="disc">
<p>In the <span class="bold">Configurations</span> area, select <span class="bold">Utility JPA Project with Java 5.0</span>.</p>
</li>
</ul>
<p>The Project Facets dialog appears.</p>
</li>
<li>
<p>On the Project Facets page, select the following options and click <span class="bold">Next</span>.</p>
<ul>
<li type="disc">
<p><span class="bold">Java Persistence 1.0</span></p>
</li>
<li type="disc">
<p><span class="bold">Java 5.0</span></p>
</li>
</ul>
<p>The JPA Facet dialog appears.</p>
</li>
<li>
<p>On the JPA Facet dialog, enter the following information:</p>
<ul>
<li type="disc">
<p>In the <span class="gui-object-action">Platform</span> field, select <code>Generic</code>.</p>
</li>
<li type="disc">
<p>In the <span class="bold">Connection</span> field, select the database connection that you created previously.</p>
</li>
</ul>
</li>
<li>
<p>In the JPA Implementation Library area, click <span class="bold">Configure default JPA implementation</span>. The JPA Preferences dialog appears.</p>
</li>
<li>
<p>Click <span class="bold">Configure user libraries</span>. The User Libraries dialog appears.</p>
</li>
<li>
<p>Click New to create a new user library, named <span class="bold">TopLink Essentials</span>, that contains the <code>toplink-essentials.jar</code> (see <a href="#BABEFHCD">"Requirements and installation"</a> for details).</p>
</li>
<li>
<p>On the User Libraries dialog, click <span class="bold">OK</span>. The JPA Facet dialog appears.</p>
</li>
<li>
<p>On the JPA Facet page, in the <span class="bold">JPA implementation</span> area select <span class="bold">Use implementation library</span> then use the drop-list to select the <code>TopLink Essentials</code> implementation library that you previously created, and click <span class="bold">Finish</span>.</p>
</li>
<li>
<p>Complete the remaining fields on the JPA Facet page and click Finish.</p>
<ul>
<li type="disc">
<p>In the <span class="gui-object-action">Persistent class management</span> area, select <code>Annotated classes must be listed in persistence.xml</code>.</p>
</li>
</ul>
</li>
</ol>
<p>Eclipse creates the JPA project and opens the JPA perspective.</p>
<div class="figure"><a id="sthref7" name="sthref7"></a>
<p class="titleinfigure">New JPA Project</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" --></div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref8" name="sthref8"></a>
<h3>Create Java classes</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 classes to the project. Later, you will change them to persistent entities.</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; Class</span>. The New Java Class dialog appears.</p>
</li>
<li>
<p>On the New <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>.</p>
<p>For this tutorial, use <code>org.eclipse.dali.example.jsf.inventory.model</code> as package and <code>Inventory</code> as the class name.</p>
<p>Eclipse adds the <span class="bold">Inventory</span> class to the Package Explorer.</p>
</li>
</ol>
<p>Repeat this procedure to add the <span class="bold">Item</span> and <span class="bold">Order</span> classes.</p>
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref9" name="sthref9"></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>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.util.Date</code>.</p>
<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="sthref10" name="sthref10"></a>
<h4>Create persistent entities and associate with a database table</h4>
<p>Now you will change each class to a persistent entity. You must also 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 JPA Structure view, select the <span class="bold">Inventory</span> entity.</p>
</li>
<li>
<p>In the JPA Details view, in the Map As field select <span class="bold">Entity</span>. Eclipse adds the <code>@Entity</code> annotation to the class.</p>
</li>
<li>
<p>In the Package Explorer view, right-click the <span class="bold">persistence.xml</span> file select <span class="bold">JPA Tools &gt; Synchronize Classes</span>. This will update the <code>persistence.xml</code> file with the newly added entity.</p>
<div class="figure"><a id="sthref11" name="sthref11"></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" -->
<p>In the <span class="gui-object-title">JPA Structure Properties</span> view, notice that Dali has automatically identified the default table, <span class="bold">Inventory</span>, associated with the entity.</p>
<div class="figure"><a id="CIHGHGAG" name="CIHGHGAG"></a>
<p class="titleinfigure">JPA Details 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>Repeat this procedure to create entities from the <span class="bold">Item</span> and <span class="bold">Order</span> classes and then associate the entities with the database tables. 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>Because the <span class="bold">Order</span> entity is named differently than the database table (ORDER_TABLE), you must explicitly create the association (as shown in <a href="#CIHGHGAG">Figure: JPA Details view for the Inventory Entity</a>). Dali adds the <code>@Table(name="ORDER_TABLE")</code> annotation to the Order entity.</p>
<p>Remember to resynchronize the <code>persistence.xml</code> file after creating and associating the entities.</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>
Depending you your specific database type, you may need to select the database schema and table information</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref12" name="sthref12"></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="sthref13" name="sthref13"></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 that each entity "does not have Id or EmbeddedId."</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">JPA Structure view</span> and select the <span class="bold">id</span> field. The JPA Details 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>
<p>Anytime you override the default, Dali adds the <code>@Column</code> annotation.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t7" headers="r1c1-t7">Insertable</td>
<td align="left" headers="r4c1-t7 r1c2-t7">The value of the <span class="bold">id</span> field is obtained from the Item entity. Select <span class="bold">False</span>.
<p>Dali adds <code>insertable = false</code> to the annotation.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r5c1-t7" headers="r1c1-t7">Updatable</td>
<td align="left" headers="r5c1-t7 r1c2-t7">The value of the <span class="bold">id</span> field is updated from the Item entity. Select <span class="bold">False</span>.
<p>Dali adds <code>updatable = false</code> to the annotation.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblruleinformal" --></li>
</ol>
<p>In the JPA Details view, the <span class="bold">id</span> field is identified as the primary key by the following icon:</p>
<div class="figure"><a id="sthref14" name="sthref14"></a>
<p class="titleinfigure">JPA Structure 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>Expand the <span class="bold">Primary Key Generation</span> area.</p>
<div class="figure"><a id="sthref15" name="sthref15"></a>
<p class="titleinfigure">Primary Key Generation for id Field</p>
<img src="img/details_view_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 in the <span class="gui-object-title">JPA Details</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, leave this as the Default (<span class="bold">Auto</span>).</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="sthref16" name="sthref16"></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 JPA Structure view, select the <span class="bold">quantity</span> field of the <span class="bold">Inventory</span> entity. The JPA Details 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 of the following types use Basic mapping: Java primitive types, wrappers of the primitive types, <code>java.lang.String</code>, <code>java.math.BigInteger</code>, <code>java.math.BigDecimal</code>, <code>java.util.Date</code>, <code>java.util.Calendar</code>, <code>java.sql.Date</code>, <code>java.sql.Time</code>, <code>java.sql.Timestamp</code>, <code>byte[]</code>, <code>Byte[]</code>, <code>char[]</code>, and <code>Character[]</code>.</p>
</li>
<li>
<div class="figure"><a id="sthref17" name="sthref17"></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 JPA Details view, 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="sthref18" name="sthref18"></a>
<p class="titleinfigure">JPA Details view 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>
<p>In the JPA Details view, use the Temporal field to select <span class="bold">Date</span>. Dali adds the <code>@Temporal(DATE)</code> annotation to the mapping.</p>
</li>
<li type="circle">
<p><span class="bold">arrivalDate</span> field to ARRIVALDATE column</p>
<p>In the JPA Details view, use the Temporal field to select <span class="bold">Date</span>. Dali adds the <code>@Temporal(DATE)</code> annotation to the mapping.</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="sthref19" name="sthref19"></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 JPA Structure view, select the <span class="bold">item</span> field of the <span class="bold">Inventory</span> entity. The JPA Details 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="sthref20" name="sthref20"></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: <code>org.eclipse.dali.example.jsf.inventory.model.Item</code>.</p>
<p>Leave the other fields with their default values.</p>
</li>
</ol>
<p>In the JPA Structure view, 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="sthref21" name="sthref21"></a>
<p class="titleinfigure">JPA Structure view 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 JPA Structure view, select the <span class="bold">version</span> field of the <span class="bold">Inventory</span> entity. The JPA Details 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="sthref22" name="sthref22"></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 JPA Details view, 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="sthref23" name="sthref23"></a>
<p class="titleinfigure">JPA Details view 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="sthref24" name="sthref24"></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 that will execute the queries at runtime, so they need to be defined:</p>
<ol type="1" start="1">
<li>
<p>Add the following query to the <span class="bold">Inventory</span> entity, immediately following the <code>@Entity</code> annotation.</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="sthref25" name="sthref25"></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>If you have not synchronized the <code>persistence.xml</code> file, do so now. 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">JPA &gt; Synchronize Classes</span>.</p>
<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, inside the <code>&lt;persistence-unit&gt;</code> element, after the final <code>&lt;class&gt;</code> element. 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>Change the persistence unit name to <span class="bold">default</span>:</p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;persistence-unit name="default"&gt;
</pre></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="sthref26" name="sthref26"></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="sthref27" name="sthref27"></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="sthref28" name="sthref28"></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="sthref29" name="sthref29"></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="sthref30" name="sthref30"></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="sthref31" name="sthref31"></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="sthref32" name="sthref32"></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="sthref33" name="sthref33"></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/webtools/dali/docs/tutorial/jsf/Dali_Tutorial_Application.zip">http://www.eclipse.org/webtools/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="sthref34" name="sthref34"></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="sthref35" name="sthref35"></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="sthref36" name="sthref36"></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="sthref37" name="sthref37"></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>
<!-- Start Footer -->
<div class="footer">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" width="86%"><a href="dcommon/html/cpyr.htm"><span class="copyrightlogo">Copyright&nbsp;&copy;&nbsp;2006, 2007,&nbsp;Oracle.&nbsp;All&nbsp;rights&nbsp;reserved.</span></a></td>
</tr>
</table>
</div>
<!-- class="footer" -->
</body>
</html>