blob: 3c57c4074dfbdf92e483f9a5b094b80f9c310b10 [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>Main Tasks | EclipseLink 2.7 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:35:14Z" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="Main Tasks" />
<meta name="relnum" content="Release 2.7" />
<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="migrhib001.htm" title="Previous" type="text/html" />
<link rel="next" href="migrhib003.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:enkkfjmsqju', 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"><font face="helvetica, arial, sans-serif"><b>EclipseLink Solutions Guide for EclipseLink</b><br />
Release 2.7</div></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="migrhib001.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="migrhib003.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 --><a id="BGBBIHFB" name="BGBBIHFB"></a><a id="TLADG462" name="TLADG462"></a>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1 class="sect1"><font face="arial, helvetica, sans-serif" color="#330099">Main Tasks</font></h1>
<p>Complete these tasks to migrate an application that uses Hibernate as its persistence provider to EclipseLink.</p>
<ul>
<li>
<p><a href="#BGBFIGDF">Task 1: Convert the Hibernate Entity Annotation</a></p>
</li>
<li>
<p><a href="#BGBCJCBF">Task 2: Convert the Hibernate Custom Sequence Generator Annotation</a></p>
</li>
<li>
<p><a href="#BGBDFADJ">Task 3: Convert Hibernate Mapping Annotations</a></p>
</li>
<li>
<p><a href="#BGBGAGJD">Task 4: Modify the persistence.xml File</a></p>
</li>
<li>
<p><a href="#BGBGDHBH">Task 5: Convert Hibernate API to EclipseLink API</a></p>
</li>
</ul>
<a id="TLADG1114" name="TLADG1114"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref49" name="sthref49"></a>
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 1: Prerequisites</font></h2>
<p>EclipseLink 2.4 or later.</p>
<p>Download EclipseLink from <code><a href="http://www.eclipse.org/eclipselink/downloads/">http://www.eclipse.org/eclipselink/downloads/</a></code>.</p>
</div>
<!-- class="sect2" -->
<a id="BGBFIGDF" name="BGBFIGDF"></a><a id="TLADG463" name="TLADG463"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 1: Convert the Hibernate Entity Annotation</font></h2>
<p>The Hibernate entity annotation, defined by the <code>org.hibernate.annotations.Entity</code> class, adds additional metadata beyond what is defined by the JPA standard <code>@Entity</code> annotation.</p>
<p><a href="#BGBJIHJB">Example 8-1</a> illustrates a sample Hibernate entity annotation. The example uses the <code>selectBeforeUpdate</code>, <code>dynamicInsert</code>, <code>dynamicUpdate</code>, <code>optimisticLock</code>, and <code>polymophism</code> attributes. Note that the Hibernate entity annotation also defines <code>mutable</code> and <code>persister</code> attributes, which are not used in this example.</p>
<div class="example"><a id="BGBJIHJB" name="BGBJIHJB"></a><a id="TLADG464" name="TLADG464"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 8-1 Sample Hibernate Entity Annotation</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
@org.hibernate.annotations.Entity(
selectBeforeUpdate = true,
dynamicInsert = true,
dynamicUpdate = true,
optimisticLock = OptimisticLockType.ALL,
polymorphism = PolymorphismType.EXPLICIT)
</pre></div>
<!-- class="example" -->
<p>The following sections describe how EclipseLink handles selects, locks, polymorphism, and dynamic updates and inserts. For more information, see "EclipseLink/Examples/JPA/Migration/Hibernate/V3Annotations" in the Eclipselink documentation, at:</p>
<p><code><a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/Hibernate/V3Annotations">http://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/Hibernate/V3Annotations</a></code></p>
<a id="TLADG465" name="TLADG465"></a>
<div class="sect3"><a id="sthref50" name="sthref50"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Convert the SelectBeforeUpdate, dynamicInsert and dynamicUpdate Attributes</font></h3>
<p>In Hibernate, the <code>selectBeforeUpdate</code> attribute specifies that Hibernate should never perform a SQL update unless it is certain that an object is actually modified. The <code>dynamicInsert</code> attribute specifies that the <code>INSERT</code> <code>SQL</code> statement should be generated at runtime and contain only the columns whose values are not null. The <code>dynamicUpdate</code> attribute specifies that the <code>UPDATE</code> <code>SQL</code> statement should be generated at runtime and can contain only those columns whose values have changed.</p>
<p>By default, EclipseLink will always insert all mapped columns and will update only the columns that have changed. If alternative operations are required, then the queries used for these operations can be customized by using Java code, SQL, or stored procedures.</p>
</div>
<!-- class="sect3" -->
<a id="TLADG466" name="TLADG466"></a>
<div class="sect3"><a id="sthref51" name="sthref51"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Convert the OptimisticLock Attribute</font></h3>
<p>In Hibernate, the <code>optimisticLock</code> attribute determines the optimistic locking strategy.</p>
<p>EclipseLink's optimistic locking functionality supports all of the Hibernate locking types and more. <a href="#BGBFBBCE">Table 8-1</a> translates locking types from Hibernate's <code>@Entity(optimisticLock)</code> attributes into EclipseLink locking policies. These policies can be configured either with the EclipseLink <code>@OptimisticLocking</code> annotation or in the EclipseLink <code>orm.xml</code> file. For more information, see @OptimisticLocking.</p>
<div class="tblhruleformalwide"><a id="TLADG467" name="TLADG467"></a><a id="sthref52" name="sthref52"></a><a id="BGBFBBCE" name="BGBFBBCE"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Table 8-1 Translating Hibernate's OptimisticLock to EclipseLink's OptimisticLocking</font></em></strong></p>
<table class="HRuleFormalWide" title="Translating Hibernate's OptimisticLock to EclipseLink's OptimisticLocking" summary="This table describes transforming Hibernate&rsquo;s OptimisticLock to TopLink&rsquo;s OptimisticLocking." dir="ltr" border="1" width="100%" frame="hsides" rules="rows" cellpadding="3" cellspacing="0">
<col width="26%" />
<col width="22%" />
<col width="*" />
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t2"><font face="Arial, Helvetica, sans-serif"><strong>Hibernate's OptimisticLock Type</strong></font></th>
<th align="left" valign="bottom" id="r1c2-t2"><font face="Arial, Helvetica, sans-serif"><strong>Description</strong></font></th>
<th align="left" valign="bottom" id="r1c3-t2"><font face="Arial, Helvetica, sans-serif"><strong>EclipseLink OptimisticLocking</strong></font></th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t2" headers="r1c1-t2">
<p><code>NONE</code></p>
</td>
<td align="left" headers="r2c1-t2 r1c2-t2">
<p>No optimistic locking</p>
</td>
<td align="left" headers="r2c1-t2 r1c3-t2">
<p>EclipseLink defaults to no optimistic locking.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t2" headers="r1c1-t2">
<p><code>VERSION</code></p>
</td>
<td align="left" headers="r3c1-t2 r1c2-t2">
<p>Use a column version</p>
</td>
<td align="left" headers="r3c1-t2 r1c3-t2">
<p>Use the JPA <code>@Version</code> annotation or the EclipseLink annotation:</p>
<p><code>@OptimisticLocking(type = OptimisticLockingType.VERSION_COLUMN)</code></p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t2" headers="r1c1-t2">
<p><code>DIRTY</code></p>
</td>
<td align="left" headers="r4c1-t2 r1c2-t2">
<p>Changed columns are compared</p>
</td>
<td align="left" headers="r4c1-t2 r1c3-t2">
<p>Use the JPA <code>@Version</code> annotation or the EclipseLink annotation:</p>
<p><code>@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)</code></p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r5c1-t2" headers="r1c1-t2">
<p><code>ALL</code></p>
</td>
<td align="left" headers="r5c1-t2 r1c2-t2">
<p>All columns are compared</p>
</td>
<td align="left" headers="r5c1-t2 r1c3-t2">
<p>Use the EclipseLink annotation:</p>
<p><code>@OptimisticLocking(type = OptimisticLockingType.ALL_COLUMNS)</code></p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="tblhruleformalwide" -->
<p>Additionally, EclipseLink allows you to compare a specific set of selected columns using the <code>OptimisticLockingType.SELECTED_COLUMNS</code> annotation. This allows you to select the critical columns that should be compared if the <code>CHANGED</code> or <code>ALL</code> strategies do not meet your needs.</p>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="BGBCJCBF" name="BGBCJCBF"></a><a id="TLADG468" name="TLADG468"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 2: Convert the Hibernate Custom Sequence Generator Annotation</font></h2>
<p>In Hibernate, the <code>@GeneratedValue</code> annotation defines the identifier generation strategy. The <code>@GenericGenerator</code> allows you to define a Hibernate-specific ID generator. <a href="#BGBHCBDG">Example 8-2</a> illustrates a custom generator for sequence values.</p>
<div class="example"><a id="BGBHCBDG" name="BGBHCBDG"></a><a id="TLADG469" name="TLADG469"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 8-2 Custom Generator for Sequence Values</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
.
.
.
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "mypackage.UUIDGenerator")
public String getTransactionGuid()
.
.
.
</pre></div>
<!-- class="example" -->
<p>In EclipseLink, a custom sequence generator can be implemented and registered by using the <code>@GeneratedValue</code> annotation. For more information, see <a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/CustomSequencing">"How to use Custom Sequencing"</a> in the EclipseLink documentation, at:</p>
<p><code><a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/CustomSequencing">http://wiki.eclipse.org/EclipseLink/Examples/JPA/CustomSequencing</a></code></p>
</div>
<!-- class="sect2" -->
<a id="BGBDFADJ" name="BGBDFADJ"></a><a id="TLADG470" name="TLADG470"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 3: Convert Hibernate Mapping Annotations</font></h2>
<p>The following sections describe how to convert various Hibernate annotations to EclipseLink annotations.</p>
<a id="TLADG471" name="TLADG471"></a>
<div class="sect3"><a id="sthref53" name="sthref53"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Convert the @ForeignKey Annotation</font></h3>
<p>In Hibernate, the <code>@ForeignKey</code> annotation allows you to define the name of the foreign key to be used during schema generation.</p>
<p>EclipseLink does generate reasonable names for foreign keys, but does not provide an annotation or <code>eclipselink-orm.xml</code> support for specifying the name to use. When migrating, the recommended solution is to have EclipseLink generate the schema (DDL) commands to a script file instead of directly on the database. The script can then be customized to use different names prior to being executed.</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>The foreign key name is not used by EclipseLink at runtime, but is required if EclipseLink attempts to drop the schema. In this case, the drop script should be generated to a file and customized to match the foreign key names used during creation.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
</div>
<!-- class="sect3" -->
<a id="TLADG472" name="TLADG472"></a>
<div class="sect3"><a id="sthref54" name="sthref54"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Convert the @Cache Annotation</font></h3>
<p>In Hibernate, the <code>@Cache</code> annotation configures the caching of entities and relationships. Because EclipseLink uses an entity cache instead of a data cache, the relationships are automatically cached. In these cases, the <code>@Cache</code> annotation should be removed during migration.When the <code>@Cache</code> annotation is used on an entity, its behavior is similar to the EclipseLink <code>@Cache</code> annotation. For more information about the <code>@Cache</code> annotation and equivalent <code>eclipselink-orm.xml</code> configuration values, see Java Persistence API (JPA) Extensions Reference for EclipseLink.</p>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="BGBGAGJD" name="BGBGAGJD"></a><a id="TLADG473" name="TLADG473"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 4: Modify the persistence.xml File</font></h2>
<p>The <code>persistence.xml</code> file is the deployment descriptor file for JPA persistence. It specifies the persistence units, and declares the managed persistence classes, the object-relational mapping, and the database connection details. <a href="#BGBBIHAD">Example 8-3</a> illustrates a <code>persistence.xml</code> file for an application that uses Hibernate. Hibernate-specific values appear in bold font.</p>
<div class="example"><a id="BGBBIHAD" name="BGBBIHAD"></a><a id="TLADG474" name="TLADG474"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 8-3 Persistence File for an Application that Uses Hibernate</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;persistence&gt;
&lt;persistence-unit name="helloworld"&gt;
<strong><code>&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;</code></strong>
&lt;jta-data-source&gt;java:/DefaultDS&lt;/jta-data-source&gt;
&lt;properties&gt;
<strong><code>&lt;property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/&gt;</code></strong>
<strong><code> &lt;property name="hibernate.hbm2ddl.auto" value="create-drop"/&gt;</code></strong>
&lt;/properties&gt;
&lt;/persistence-unit&gt;
&lt;/persistence&gt;
</pre></div>
<!-- class="example" -->
<a id="TLADG475" name="TLADG475"></a>
<div class="sect3"><a id="sthref55" name="sthref55"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Modified persistence.xml File</font></h3>
<p><a href="#BGBHEIEJ">Example 8-4</a> illustrates a <code>persistence.xml</code> file modified for an application that uses EclipseLink. Key differences include the value for the persistence provider. For EclipseLink, this value is <code>org.eclipse.persistence.jpa.PersistenceProvider</code>. The names of EclipseLink-specific properties are typically be prefixed by <code>eclipselink</code>, for example, <code>eclipselink.target-database</code>. EclipseLink-specific values appear in bold font.</p>
<div class="example"><a id="BGBHEIEJ" name="BGBHEIEJ"></a><a id="TLADG476" name="TLADG476"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 8-4 Persistence File Modified for EclipseLink</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;xml version="1.0" encoding="UTF-8"?&gt;
&lt;persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&gt;
&lt;persistence-unit name="helloworld"&gt;
<strong><code>&lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;</code></strong>
&lt;jta-data-source&gt;java:/DefaultDS&lt;/jta-data-source&gt;
&lt;!-- For Java SE applications, entity classes must be specified for EclipseLink weaving. For Java EE applications, the classes are found automatically. --&gt;
&lt;class&gt;Todo&lt;/class&gt;
&lt;properties&gt;
<strong><code>&lt;property name="eclipselink.ddl-generation" value="drop-and-create-tables"/&gt;</code></strong>
<strong><code> &lt;property name="eclipselink.ddl-generation.output-mode" value="database"/&gt;</code></strong>
<strong><code>&lt;property name="eclipselink.logging.level" value="FINE"/&gt;</code></strong>
&lt;/properties&gt;
&lt;/persistence-unit&gt;
&lt;/persistence&gt;
</pre></div>
<!-- class="example" --></div>
<!-- class="sect3" -->
<a id="TLADG477" name="TLADG477"></a>
<div class="sect3"><a id="sthref56" name="sthref56"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Drop and Create the Database Tables</font></h3>
<p>For production environments, you would usually have the schema set up on the database. The following properties defined in the persistence unit are more suitable for examples and demonstrations. These properties will instruct EclipseLink to automatically drop and create database tables. Any previously existing tables will be removed.</p>
<p>To use the Drop and Create Database Tables feature, add the following properties to the <code>persistence.xml</code> file.</p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;property name="eclipselink.ddl-generation" value="drop-and-create-tables"/&gt;
&lt;property name="eclipselink.ddl-generation.output-mode" value="database"/&gt;
</pre>
<p>For more information on this feature, see the <code>drop-and-create-tables</code> entry in "ddl-generation" in <em>Java Persistence API (JPA) Extensions Reference for EclipseLink</em>.</p>
</div>
<!-- class="sect3" -->
<a id="TLADG1115" name="TLADG1115"></a>
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref57" name="sthref57"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Create or Extend Database Tables</font></h3>
<p>The Create or Extend Database Tables feature allows you match the database schema to the object model by creating new database tables or by modifying existing tables. You can modify existing tables by specifying field name changes and by add and removing fields.</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>In the current release, the Create or Extend Database Tables feature will not rename or delete existing columns. It will only add missing table columns.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<p>The Create or Extend Database Tables feature reduces the need to repopulate test data. You avoid the need to use the Drop and Create Database Tables feature when the schema changes, due to changes in the object model. The Create or Extend Database Tables feature can also be used with extensibility to add table columns.</p>
<p>To use the Create or Extend Database Tables feature, add the following properties to the <code>persistence.xml</code> file. When the context is loaded, EclipseLink will query the database for each table required in the persistence unit and use the results to determine if the table needs to be created or extended.</p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;property name="eclipselink.ddl-generation" value="create-or-extend-tables" /&gt;
&lt;property name="eclipselink.ddl-generation.output-mode" value="database" /&gt;
</pre>
<p>For more information on this feature, see the <code>create-or-extend-tables</code> entry in "ddl-generation" in <em>Java Persistence API (JPA) Extensions Reference for EclipseLink</em>.</p>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="BGBGDHBH" name="BGBGDHBH"></a><a id="TLADG478" name="TLADG478"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 5: Convert Hibernate API to EclipseLink API</font></h2>
<p><a href="#BGBDAHCF">Table 8-2</a> describes the Hibernate classes that are commonly used in a JPA project and their equivalent EclipseLink (JPA) interfaces. All of the Hibernate classes are in the <code>org.hibernate</code> package. All of the JPA interfaces (and the <code>Persistence</code> class) are in the <code>javax.persistence</code> package.</p>
<p>For information about the EclipseLink API, see <em>Java API Reference for EclipseLink</em>.</p>
<div class="tblhruleformalwide"><a id="TLADG479" name="TLADG479"></a><a id="sthref58" name="sthref58"></a><a id="BGBDAHCF" name="BGBDAHCF"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Table 8-2 Hibernate Classes and Equivalent JPA Interfaces</font></em></strong></p>
<table class="HRuleFormalWide" title="Hibernate Classes and Equivalent JPA Interfaces" summary="This table describes Hibernate classes and the equivalent JPA interfaces." dir="ltr" border="1" width="100%" frame="hsides" rules="rows" cellpadding="3" cellspacing="0">
<col width="21%" />
<col width="27%" />
<col width="*" />
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t5"><font face="Arial, Helvetica, sans-serif"><strong>org.hibernate</strong></font></th>
<th align="left" valign="bottom" id="r1c2-t5"><font face="Arial, Helvetica, sans-serif"><strong>javax.persistence</strong></font></th>
<th align="left" valign="bottom" id="r1c3-t5"><font face="Arial, Helvetica, sans-serif"><strong>Description</strong></font></th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t5" headers="r1c1-t5">
<p><code>cfg.Configuration</code></p>
</td>
<td align="left" headers="r2c1-t5 r1c2-t5">
<p><code>Persistence</code></p>
</td>
<td align="left" headers="r2c1-t5 r1c3-t5">
<p>Provides a bootstrap class that configures the session factory (in Hibernate) or the entity manager factory (in JPA). It is generally used to create a single session (or entity manager) factory for the JVM.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t5" headers="r1c1-t5">
<p><code>SessionFactory</code></p>
</td>
<td align="left" headers="r3c1-t5 r1c2-t5">
<p><code>EntityManagerFactory</code></p>
</td>
<td align="left" headers="r3c1-t5 r1c3-t5">
<p>Provides APIs to open Hibernate sessions (or JPA entity managers) to process a user request. Generally, a session (or entity manager) is opened per thread processing client requests.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t5" headers="r1c1-t5">
<p><code>Session</code></p>
</td>
<td align="left" headers="r4c1-t5 r1c2-t5">
<p><code>EntityManager</code></p>
</td>
<td align="left" headers="r4c1-t5 r1c3-t5">
<p>Provides APIs to store and load entities to and from the database. It also provides APIs to get a transaction and create a query.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r5c1-t5" headers="r1c1-t5">
<p><code>Transaction</code></p>
</td>
<td align="left" headers="r5c1-t5 r1c2-t5">
<p><code>EntityTransaction</code></p>
</td>
<td align="left" headers="r5c1-t5 r1c3-t5">
<p>Provides APIs to manage transactions.</p>
</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r6c1-t5" headers="r1c1-t5">
<p><code>Query</code></p>
</td>
<td align="left" headers="r6c1-t5 r1c2-t5">
<p><code>Query</code></p>
</td>
<td align="left" headers="r6c1-t5 r1c3-t5">
<p>Provides APIs to execute queries.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="tblhruleformalwide" --></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="migrhib001.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="migrhib003.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 />
<font size="-2">Copyright&nbsp;&copy;&nbsp;2014,&nbsp;Oracle&nbsp;and/or&nbsp;its&nbsp;affiliates.&nbsp;All&nbsp;rights&nbsp;reserved.</font> <a href="../../dcommon/html/cpyr.htm"><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; 2014 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>