cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Cayenne Documentation > Tutorial Starting Mapping Project
Date Sun, 20 Dec 2009 17:24:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Tutorial
Starting Mapping Project</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Andrus
     <div class="notificationGreySide">
         <h3><a name="TutorialStartingMappingProject-CreateanewProjectinEclipse"></a>Create
a new Project in Eclipse</h3>

<p>In Eclipse select "File &gt; New &gt; Other..." and then "Maven &gt;
Maven Project". Click "Next". On the following screen check "Create a simple project" checkbox
and click "Next" again. In the dialog shown on the screenshot below, fill the "Group Id" and
"Artifact Id" fields and click "Finish".</p>

<h3><a name="TutorialStartingMappingProject-StartCayenneModeler"></a>Start

<p>Start CayenneModeler by double-clicking the appropriate startup file in the <tt>bin</tt>
directory of Cayenne installation (if the Modeler does not start, see <a href="/confluence/display/CAYDOC/Running+CayenneModeler"
title="Running CayenneModeler">this page</a> for more information).</p>

<p>Now you will create both database schema definition and object mapping from scratch
using CayenneModeler. Note that in cases when you already have a legacy database, this process
can be automated by using reverse engineering features of the Modeler (<tt>"Tools &gt;
Reengineer Database Schema"</tt>). Still understanding how manual mapping works is important.</p>

<h3><a name="TutorialStartingMappingProject-CreateNewCayenneProject"></a>Create
New Cayenne Project</h3>

<p>Click on the "New Project" button on Welcome screen. <br/>
<img src="/confluence/download/attachments/10517/Picture 1.png" align="absmiddle" border="0"

<p>A new project will appear that contains a single DataDomain. The meaning of a DataDomain
is explained elsewhere in the User Guide. For now it is sufficient to understand that DataDomain
is the root of your mapping project:</p>

<p><img src="/confluence/download/attachments/10517/modeler-datadomain.jpg" align="absmiddle"
border="0" /></p>

<h3><a name="TutorialStartingMappingProject-Addadatabaseadaptor"></a>Add
a database adaptor</h3>

<p>Go to <tt>"Tools &gt; Preferences &gt; ClassPath"</tt> and add
a <tt>derby.jar</tt> file to the list of "Custom ClassPath" entries to allow CayenneModeler
to work with Derby. When done click "Save". If you are using a database other then Derby,
you should enter a location of that database JDBC driver instead.</p>

<p><img src="/confluence/download/attachments/10517/modeler-classpath.jpg" align="absmiddle"
border="0" /></p>

<h3><a name="TutorialStartingMappingProject-CreateDataNode"></a>Create DataNode</h3>

<p>The next project object you will create is a DataNode that is a descriptor of the
physical database. With "UntitledDomain" selected on the left, click on "Create DataNode"
button on the toolbar (or select <tt>"Project &gt; Create DataNode"</tt> from
the menu.</p>

<p>A new DataNode is displayed. You can leave the defaults in the "DataNode Configuration"
section unchanged, but you need to specify JDBC Configuration parameters. For embedded Derby
database you can enter the following settings, replacing "testdb" with an absolute path of
the directory on your filesystem where you want the database to be created (e.g., on Windows
you may specify <tt>jdbc:derby:c:/testdb;create=true</tt>):</p>

<p><img src="/confluence/download/attachments/10517/modeler-datanode.jpg" align="absmiddle"
border="0" /></p>

<h3><a name="TutorialStartingMappingProject-CreateDataMap"></a>Create DataMap</h3>

<p>Now you will create a DataMap - an object that holds all the mapping information.
To do this, click on "Create DataMap" button (or select a corresponding menu item). Note that
the newly created DataMap is automatically linked to the DataNode that you created in the
previous step. If there is more than one DataNode, you may need to link a DataMap to the correct
node manually. In other words a DataMap within DataDomain must point to a database described
by the map.</p>

<p>You can leave all the DataMap defaults unchanged except for one - Java Package. Enter
"cayenne.tutorial" for the default package name that later will be used for all persistent

<p><img src="/confluence/download/attachments/10517/modeler-datamap.jpg" align="absmiddle"
border="0" /></p>

<h3><a name="TutorialStartingMappingProject-SavetheProject"></a>Save the

<p>Before you proceed with the actual mapping, let's save the project. Click on "Save"
button in the toolbar and navigate to the "cayenne-tutorial" Eclipse project folder that was
created earlier. Cayenne mapping files must be accessible in the application CLASSPATH, so
let's save them under "cayenne-tutorial/src" folder. Now if you go back to Eclipse, right
click on "cayenne-tutorial" project and select "Refresh", you will see three Cayenne XML files:</p>

<p><img src="/confluence/download/attachments/10517/eclipse-xmlfiles.jpg" align="absmiddle"
border="0" /></p>

<hr />
<p><b>Next Step: <a href="/confluence/display/CAYDOC/Tutorial+Object+Relational+Mapping"
title="Tutorial Object Relational Mapping">Tutorial Object Relational Mapping</a></b></p>
<hr />
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message