blob: 56f08836ac3709f1899f9f3e8b0209c9041b55b8 [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>
<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" />
<title>Descriptor Files | EclipseLink 3.0.x Understanding EclipseLink</title>
<meta name="generator" content="Oracle DARB XHTML Converter (Mode = document) - Version 1.0.22 Build 1" />
<meta name="date" content="2014-06-10T10:39:52Z" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="Descriptor Files" />
<meta name="relnum" content="3.0" />
<link rel="stylesheet" type="text/css" href="../../dcommon/style.css" media="screen" />
<link rel="copyright" href="../../dcommon/html/cpyr.htm" title="Copyright" type="text/html" />
<link rel="start" href="../../index.htm" title="Home" type="text/html" />
<link rel="contents" href="toc.htm" title="Contents" type="text/html" />
<link rel="prev" href="descriptors002.htm" title="Previous" type="text/html" />
<link rel="next" href="mappingintro.htm" title="Next" type="text/html" />
<!-- START: Disqus --><script type="text/javascript"> var disqus_developer = 0; </script><!-- END: Disqus --><!-- START: Sharethis --><script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript" src="http://s.sharethis.com/loader.js"></script> <!-- END: Sharethis --></head>
<body bgcolor="#FFFFFF"><iframe id="docheader" frameborder="0" framemargin="0" scrolling="no" src="../../dcommon/header.html"></iframe><script src="http://www.google.com/jsapi" type="text/javascript"></script><script type="text/javascript"> google.load('search', '1', {language : 'en'}); google.setOnLoadCallback(function() { var customSearchOptions = {}; var googleAnalyticsOptions = {}; googleAnalyticsOptions['queryParameter'] = 'q'; googleAnalyticsOptions['categoryParameter'] = ''; customSearchOptions['googleAnalyticsOptions'] = googleAnalyticsOptions; var customSearchControl = new google.search.CustomSearchControl( '016171230611334810008:mdbgdwjv8zu', customSearchOptions); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); var options = new google.search.DrawOptions(); options.setSearchFormRoot('cse-search-form'); customSearchControl.draw('cse', options); }, true);</script><link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" /><div id="cse" style="width:100%;"></div>
<div class="header"><a id="top" name="top"></a>
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" valign="top"><div class="booktitle">Understanding EclipseLink,
<b>3.0</b><br /></font></td>
<td valign="bottom" align="right" width="144">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>&nbsp;</td>
<td align="center" valign="top"><a href="toc.htm"><img src="../../dcommon/images/contents.png" alt="Go To Table Of Contents" border="0" height="16" width="16" /><br />
</td><td>&nbsp;</td><td align="center"><a href="../../" target="_top" class="external text" title="Search" rel="nofollow"><img src="../../dcommon/images/search.png" alt="Search" style="border:0;" /><br /><span class="mini"></span></a></td><td>&nbsp;</td><td align="center"><a href="../eclipselink_otlcg.pdf" title="PDF" target="_blank"><img src="../../dcommon/images/pdf_icon.png" style="padding-right:5px;border:0" alt="PDF"></a></td>
</tr>
</table>
</td>
</tr>
</table>
<hr />
<table class="navigation simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100" align="center">
<tr>
<td align="center"><a href="descriptors002.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="mappingintro.htm"><img src="../../dcommon/images/rarrow.png" alt="Next" border="0" height="16" width="16" /></a></td>
<td>&nbsp;</td>
</tr>
</table>
</div>
<!-- class="header" -->
<div class="ind"><!-- End Header -->
<div class="sect1"><!-- infolevel="all" infotype="General" --><a id="sthref30" name="sthref30"></a>
<h1 class="sect1"><font face="arial, helvetica, sans-serif" color="#330099">Descriptor Files</font></h1>
<p>The following sections describe the descriptor files that can be used for object-relational and MOXy mapping.</p>
<ul>
<li>
<p><a href="#BCFDEAGB">Using orm.xml for Object-Relational Mappings</a></p>
</li>
<li>
<p><a href="#BCFDDBGI">Using eclipselink-orm.xml for EclipseLink Object-Relational Mappings</a></p>
</li>
<li>
<p><a href="#CHDIJFAC">Using eclipselink-oxm.xml for EclipseLink MOXy Mappings</a></p>
</li>
</ul>
<a id="BCFDEAGB" name="BCFDEAGB"></a><a id="OTLCG94268" name="OTLCG94268"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Using orm.xml for Object-Relational Mappings</font></h2>
<p>Use the <code>orm.xml</code> file to apply the metadata to the persistence unit. This metadata is a union of all the mapping files and the annotations (if there is no <code>xml-mapping-metadata-complete</code> element). If you use one mapping <code>orm.xml</code> file for your metadata and place this file in a <code>META-INF</code> directory on the classpath, then you do not need to explicitly list it. The persistence provider will automatically search for this file (<code>orm.xml</code>) and use it.</p>
<p>The schema for the JPA 2.0 <code>orm.xml</code> is <code>orm_2_0.xsd</code>. (<code><a href="http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">http://java.sun.com/xml/ns/persistence/orm_2_0.xsd</a></code>)</p>
<p>If you use a different name for your mapping files or place them in a different location, you must list them in the <code>mapping-file</code> element of the <code>persistence.xml</code> file.</p>
</div>
<!-- class="sect2" -->
<a id="BCFDDBGI" name="BCFDDBGI"></a><a id="OTLCG145" name="OTLCG145"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Using eclipselink-orm.xml for EclipseLink Object-Relational Mappings</font></h2>
<p>EclipseLink supports an extended JPA <code>orm.xml</code> mapping configuration file called <code>eclipselink-orm.xml</code>. This mapping file can be used in place of JPA's standard mapping file or can be used to override a JPA mapping file. In additional to allowing all of the standard JPA mapping capabilities it also includes advanced mapping types and options.</p>
<p>For more information on the <code>eclipselink-orm.xml</code> file, see "eclipselink-orm.xml Schema Reference" in <em>Jakarta Persistence API (JPA) Extensions Reference for EclipseLink</em>.</p>
<div align="center">
<div class="inftblnote"><br />
<table class="Note oac_no_warn" summary="" border="1" width="80%" frame="hsides" rules="groups" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="note"><img src="../../dcommon/images/note_icon.png" width="16" height="16" alt="Note" style="vertical-align:middle;padding-right:5px;" />Note:</p>
<p>Using this mapping file enables many EclipseLink advanced features, but it may prevent the persistence unit from being portable to other JPA implementations.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<p>For more information, on overriding values, see:</p>
<ul>
<li>
<p>"XML Overriding Rules" in the JPA Specification.</p>
<p><code><a href="http://jcp.org/en/jsr/detail?id=338">http://jcp.org/en/jsr/detail?id=338</a></code></p>
</li>
<li>
<p>The schema for <code>eclipselink-orm.xml</code> is <code>eclipselink_orm_2_2.xsd</code>:</p>
<p><code><a href="http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_2.xsd">http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_2.xsd</a></code></p>
</li>
</ul>
<a id="OTLCG94269" name="OTLCG94269"></a>
<div class="sect3"><a id="sthref31" name="sthref31"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Overriding and Merging Mapping Information</font></h3>
<p>To override the <code>orm.xml</code> file's mapping, you must define the <code>META-INF/eclipselink-orm.xml</code> file in the project. The contents of <code>eclipselink-orm.xml</code> override <code>orm.xml</code> and any other JPA mapping file specified in the persistence unit. If there are overlapping specifications in multiple ORM files, the files are merged if there are no conflicting entities.</p>
<p>For more information, see "Overriding and Merging" in <em>Jakarta Persistence API (JPA) Extensions Reference for EclipseLink</em>.</p>
</div>
<!-- class="sect3" -->
<a id="OTLCG94270" name="OTLCG94270"></a>
<div class="sect3"><a id="sthref32" name="sthref32"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Validating the XML Schema</font></h3>
<p>By default the content of your <code>.orm</code> XML file is not validated against the JPA <code>.orm</code> XML schema.</p>
<p>During development it is a good idea to validate your <code>.orm</code> XML file against the schema to ensure it is valid. In EclipseLink, validating the <code>.orm</code> XML schema can be enabled using the persistence unit property "<code>eclipselink.orm.validate.schema</code>" in your <code>persistence.xml</code> file.</p>
</div>
<!-- class="sect3" -->
<a id="OTLCG94271" name="OTLCG94271"></a>
<div class="sect3"><a id="sthref33" name="sthref33"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Advantages and Disadvantages of Using XML</font></h3>
<p>Some advantages of using XML instead of annotations include:</p>
<ul>
<li>
<p>No coupling between the metadata and the source code</p>
</li>
<li>
<p>Compliance with the existing, pre-EJB 3.0 development process</p>
</li>
<li>
<p>Support in IDEs and source control systems</p>
</li>
</ul>
<p>The main disadvantages of mapping with XML include:</p>
<ul>
<li>
<p>It is inherently complex (when compared to annotations)</p>
</li>
<li>
<p>The need for replication of the code context (that is, defining the structure in both the XML and the source code)</p>
</li>
</ul>
<p>For more information, see Chapter 10 "Metadata Annotations" in the JPA Specification:</p>
<p><code><a href="http://jcp.org/en/jsr/detail?id=338">http://jcp.org/en/jsr/detail?id=338</a></code></p>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="CHDIJFAC" name="CHDIJFAC"></a><a id="OTLCG162" name="OTLCG162"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Using eclipselink-oxm.xml for EclipseLink MOXy Mappings</font></h2>
<p>You can use Java annotations to specify JAXB features in your projects. In addition to Java annotations, EclipseLink provides an XML mapping configuration file called <code>eclipselink-oxm.xml</code>. This mapping file contains the standard JAXB mappings and configuration options for advanced mapping types. You can use the <code>eclipselink-oxm.xml</code> file in place of or to override JAXB annotations in source code.</p>
<div align="center">
<div class="inftblnote"><br />
<table class="Note oac_no_warn" summary="" border="1" width="80%" frame="hsides" rules="groups" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="note"><img src="../../dcommon/images/note_icon.png" width="16" height="16" alt="Note" style="vertical-align:middle;padding-right:5px;" />Note:</p>
<p>Using this mapping file will enable many advanced features but it can prevent the model from being portable to other JAXB implementations.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
</div>
<!-- class="sect2" --></div>
<!-- class="sect1" --></div>
<!-- class="ind" -->
<!-- Start Footer -->
<div class="footer">
<hr />
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<col width="33%" />
<col width="*" />
<col width="33%" />
<tr>
<td valign="bottom">
<table class="navigation simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100" align="center">
<col width="*" />
<col width="48%" />
<col width="48%" />
<tr>
<td>&nbsp;</td>
<td align="center"><a href="descriptors002.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="mappingintro.htm"><img src="../../dcommon/images/rarrow.png" alt="Next" border="0" height="16" width="16" /></a></td>
</tr>
</table>
</td>
<td align="center" width="34%"><a href="http://www.eclipse.org/eclipselink/" title="EclipseLink home"><img src="../../dcommon/images/ellogo.png" alt="EclipseLink" width="150" border="0" /></a><br />
<td valign="bottom" align="right">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="225">
<tr>
<td>&nbsp;</td>
<td align="center" valign="top"><a href="toc.htm"><img src="../../dcommon/images/contents.png" alt="Go To Table Of Contents" border="0" height="16" width="16" /><br />
</td><td>&nbsp;</td><td align="center"><a href="../../" target="_top" class="external text" title="Search" rel="nofollow"><img src="../../dcommon/images/search.png" alt="Search" style="border:0;" /><br /><span class="mini"></span></a></td><td>&nbsp;</td><td align="center"><a href="../eclipselink_otlcg.pdf" title="PDF" target="_blank"><img src="../../dcommon/images/pdf_icon.png" style="padding-right:5px;border:0" alt="PDF"></a></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<!-- class="footer" -->
<div id="copyright">Copyright &copy; 2012 by The Eclipse Foundation under the <a href="http://www.eclipse.org/org/documents/epl-v10.php">Eclipse Public License (EPL)</a><br /> <script type="text/javascript">var LastUpdated = document.lastModified;document.writeln ("Updated: " + LastUpdated);</script> </div><!-- START: Analytics --><script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-1608008-2']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script><!-- END: Analytics --><!-- START: Sharethis --><script>var options={ "publisher": "e2fe9e07-fab6-4f84-83ea-0991b429842c", "position": "right", "ad": { "visible": false, "openDelay": 5, "closeDelay": 0}};var st_hover_widget = new sharethis.widgets.hoverbuttons(options);</script><!-- END: Sharethis --></body>
</html>