Skip to main content
blob: ea670ab0d1179c0d334ad8ced6996ba520d35751 (plain) (tree)





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en" lang="en">
<!-- Run date = May 15, 2007 9:04:20 -->
<meta name="OAC_IGNORE_SKIP_NAV" content="true" />
<title>Mapping an entity</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="" />
<meta name="doctitle" content="Mapping an entity" />
<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" />
<link rel="contents" href="toc.htm" title="Contents" type="text/html" />
<p><a id="BABHACAF" name="BABHACAF"></a></p>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr valign="bottom">
<td align="left" width="86%">
<h1>Mapping an entity</h1>
<p><a id="sthref17" name="sthref17"></a><a id="sthref18" name="sthref18"></a>This quick start shows how to map fields in a Java persistent entity. Before beginning, add the following fields to the Address class:</p>
<pre xml:space="preserve" class="oac_no_warn">
private Long id;
private String city;
private String country;
private String stateOrProvince;
private String postalCode;
private String street;

<p>Eclipse updates the Address entity in the JPA Structure view to show its fields:</p>
<div class="figure"><a id="sthref19" name="sthref19"></a>
<p class="titleinfigure">Address Entity and Fields</p>
<img src="img/persistence_outline_fields.png" alt="Address entity and its fields in the JPA Structure view." title="Address entity and its fields in the JPA Structure view." /><br /></div>
<!-- class="figure" -->
<p>You will also need to add the following columns to the ADDRESS database table:</p>
<pre xml:space="preserve" class="oac_no_warn">
NUMBER(10,0) ADDRESS_ID (primary key)
<pre xml:space="preserve" class="oac_no_warn">
<p>Now we are ready to map each fields in the Address class to a column in the database table.</p>
<ol type="1" start="1">
<p>Select the <span class="gui-object-action">id</span> field in the JPA Details view.</p>
<p>In the JPA Details view:</p>
<li type="disc">
<p>For the Map As field, select <span class="bold">Id</span></p>
<li type="disc">
<p>For the Column field, select <span class="bold">ADDRESS_ID</span>.</p>
<div class="figure"><a id="sthref20" name="sthref20"></a>
<p class="titleinfigure">JPA Details View for addressId Field</p>
<img src="img/persistence_view_addressid.png" alt="JPA Details view for the id field." title="JPA Details view for the id field." /><br /></div>
<!-- class="figure" -->
<p>Eclipse adds the following annotations to the Address entity:</p>
<pre xml:space="preserve" class="oac_no_warn">

<p>Map each of the following fields (as <span class="bold">Basic</span> mappings) to the appropriate database column:</p>
<div class="inftblhruleinformal">
<table class="HRuleInformal" title="This table describes the mappings for each of the fields in the Address entity." summary="This table describes the mappings for each of the fields in the Address entity." dir="ltr" border="1" width="100%" frame="border" rules="all" cellpadding="3" cellspacing="0">
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t4">Field</th>
<th align="left" valign="bottom" id="r1c2-t4">Map As</th>
<th align="left" valign="bottom" id="r1c3-t4">Database Column</th>
<tr align="left" valign="top">
<td align="left" id="r2c1-t4" headers="r1c1-t4">city</td>
<td align="left" headers="r2c1-t4 r1c2-t4">Basic</td>
<td align="left" headers="r2c1-t4 r1c3-t4">CITY</td>
<tr align="left" valign="top">
<td align="left" id="r3c1-t4" headers="r1c1-t4">country</td>
<td align="left" headers="r3c1-t4 r1c2-t4">Basic</td>
<td align="left" headers="r3c1-t4 r1c3-t4">COUNTRY</td>
<tr align="left" valign="top">
<td align="left" id="r4c1-t4" headers="r1c1-t4">postalCode</td>
<td align="left" headers="r4c1-t4 r1c2-t4">Basic</td>
<td align="left" headers="r4c1-t4 r1c3-t4">P_CODE</td>
<tr align="left" valign="top">
<td align="left" id="r5c1-t4" headers="r1c1-t4">provinceOrState</td>
<td align="left" headers="r5c1-t4 r1c2-t4">Basic</td>
<td align="left" headers="r5c1-t4 r1c3-t4">PROVINCE</td>
<tr align="left" valign="top">
<td align="left" id="r6c1-t4" headers="r1c1-t4">street</td>
<td align="left" headers="r6c1-t4 r1c2-t4">Basic</td>
<td align="left" headers="r6c1-t4 r1c3-t4">STREET</td>
<br /></div>
<!-- class="inftblhruleinformal" --></li>
<p>Notice that Dali will automatically map some fields to the correct database column (such as the <span class="bold">city</span> field to the CITY column) if the names are identical.</p>
<p>Refer to the <a href="getting_started006.htm#BABCDECJ">Dali basic tutorial</a> to map a complete object model using basic and relational mappings.</p>
<!-- class="sect2" -->
<!-- class="sect1" -->
<!-- Start Footer -->
<div class="footer">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<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>
<!-- class="footer" -->

Back to the top