blob: cfef5a744c86eec36bb6782758a1bbf29f180648 [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>Implementing the Solution | 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:15Z" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="Implementing the Solution" />
<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="nonrelational_db001.htm" title="Previous" type="text/html" />
<link rel="next" href="nonrelational_db003.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="nonrelational_db001.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="nonrelational_db003.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="A1582967" name="A1582967"></a><a id="TLADG1023" name="TLADG1023"></a>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1 class="sect1"><font face="arial, helvetica, sans-serif" color="#330099">Implementing the Solution</font></h1>
<p>This section contains the following tasks for converting objects to and from JSON documents.</p>
<ul>
<li>
<p><a href="#BABEBADB">Task 1: Prerequisites</a></p>
</li>
<li>
<p><a href="#BABIGCEC">Task 2: Mapping the Data</a></p>
</li>
<li>
<p><a href="#BABEIBBG">Task 3: Defining IDs</a></p>
</li>
<li>
<p><a href="#BABFIIFG">Task 4: Defining Mappings</a></p>
</li>
<li>
<p><a href="#BABFIJAA">Task 5: Using Locking</a></p>
</li>
<li>
<p><a href="#BABIIDED">Task 6: Defining Queries</a></p>
</li>
<li>
<p><a href="#BABFJIJE">Task 7: Connecting to the Database</a></p>
</li>
</ul>
<a id="BABEBADB" name="BABEBADB"></a><a id="TLADG1024" name="TLADG1024"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 1: Prerequisites</font></h2>
</div>
<!-- class="sect2" -->
<a id="BABIGCEC" name="BABIGCEC"></a><a id="TLADG1025" name="TLADG1025"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 2: Mapping the Data</font></h2>
<p>You can configure mappings to NoSQL data with the EclipseLink <code>@NoSQL</code> annotation and <code>&lt;no-sql&gt;</code> XML element. The <code>@NoSQL</code> annotation defines the class as mapping to non-relational data. You can use <code>@NoSQL</code> with JPA Entity or Embeddable classes.</p>
<p>The <code>@NoSQL</code> annotation allows you to specify the <code>dataType</code> and <code>dataFormat</code> of the data. The <code>dataType</code> will vary, depending on your NoSQL datasource:</p>
<ul>
<li>
<p>For MongoDB, <code>dataType</code> is the collection name that the JSON documents are stored to.</p>
</li>
<li>
<p>For Oracle NoSQL, <code>dataType</code> is the first part of the major key value.</p>
</li>
</ul>
<p>The <code>dataFormat</code> depends on the type structure (data format) of data being stored.</p>
<ul>
<li>
<p>For MongoDB, use <code>MAPPED</code> for its structured database.</p>
</li>
<li>
<p>For Oracle NoSQL, use <code>MAPPED</code> (for key/value data) or <code>XML</code> (for a single XML document).</p>
</li>
</ul>
<p><a href="#BABBBHHD">Example 21-1</a> illustrates how to use <code>@NoSQL</code> with <code>@Entity</code> and <code>@Embeddable</code> classes.</p>
<div class="example"><a id="BABBBHHD" name="BABBBHHD"></a><a id="TLADG1026" name="TLADG1026"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-1 Using @NoSql Annotation with JSON</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
@Entity
<strong>@NoSQL(dataType="orders", dataFormat=DataFormatType.MAPPED)</strong>
public class Order {
@Id
@GeneratedValue
@Field(name="_id")
private long id;
@Basic
@Field(name="description")
private String description;
@Embedded
@Field(name="deliveryAddress")
private Address deliveryAddress
@ElementCollection
@Field(name="orderLines")
private List&lt;OrderLine&gt; orderLines;
@ManyToOne
@JoinField(name="customerId")
private Customer customer;
}
@Embeddable
<strong>@NoSQL(dataFormat=DataFormatType.MAPPED)</strong>
public class OrderLine {
@Field(name="lineNumber")
private int lineNumber;
@Field(name="itemName")
private String itemName;
@Field(name="quantity")
private int quantity;
}
</pre></div>
<!-- class="example" --></div>
<!-- class="sect2" -->
<a id="BABEIBBG" name="BABEIBBG"></a><a id="TLADG1027" name="TLADG1027"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 3: Defining IDs</font></h2>
<p>With EclipseLink, you can use any field (or set of fields) as your ID when using a non-relational database, just like any other relational Entity. You can use a <em>natural</em> ID (that is, assigned by the application) or a <em>generated</em> ID (that is, assigned by EclipseLink).</p>
<p>MongoDB also requires an <code>_id</code> field in every document. If no <code>_id</code> field is present, Mongo will automatically generate and assign the <code>_id</code> field using an OID (object identifier), which is similar to a UUID (universally unique identifier).</p>
<ul>
<li>
<p>To use a natural ID as the Mongo ID, simply name the field as <code>_id</code> by using the <code>@Field</code> (or <code>@Column</code>) annotation without any of the relational details.</p>
<p>For example:</p>
<pre xml:space="preserve" class="oac_no_warn">
@Field(name="_id")
private long id;
</pre></li>
<li>
<p>To use the generated Mongo OID as your ID, simply include <code>@Id</code>, <code>@GeneratedValue</code>, and <code>@Field(name="_id")</code> annotations in the object's ID field mapping.</p>
<p>The <code>@GeneratedValue</code> tells EclipseLink to use the Mongo OID to generate this ID value. To use a UUID instead of the Mongo OID, use the @UUIDGenerator annotation.</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>MongoDB does not support <code>@SequenceGenerator</code> or <code>@TableGenerator</code> nor the <code>IDENTITY</code>, <code>TABLE</code>, and <code>SEQUENCE</code> generation types.</p>
<p>The ID of the Mongo OID or UUID is not a numerical value; you must map it as a <code>String</code> or <code>byte[]</code>.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<p>For example:</p>
<pre xml:space="preserve" class="oac_no_warn">
@Id
@GeneratedValue
@Field(name="_id")
private String id;
</pre></li>
</ul>
</div>
<!-- class="sect2" -->
<a id="BABFIIFG" name="BABFIIFG"></a><a id="TLADG1028" name="TLADG1028"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 4: Defining Mappings</font></h2>
<p>With non-relational databases, EclipseLink maps objects to structured data such as XML or JSON. NoSQL supports all existing JPA mapping annotations and XML, including embedded data and embedded collections. If you do not define a mapping annotation (or XML) for an attribute EclipseLink uses the default mapping.</p>
<a id="TLADG1029" name="TLADG1029"></a>
<p><b><font face="arial, helvetica, sans-serif" color="#330099">Basic Mappings</font></b></p>
<p>Because the NoSQL defaults follow the JPA defaults, most simple mappings do not require any configuration. Field names used in the Mongo BSON document will mirror the object attribute names (in uppercase). To use a different BSON field name, use the <code>@Field</code> annotation.</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>Do not use <code>@Column</code> or <code>@JoinColumn</code>. Instead use <code>@Field</code> and <code>@JoinField</code>. Additionally, the <code>@JoinTable</code> and <code>@CollectionTable</code> annotations are not supported or required.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<a id="BABIFJJG" name="BABIFJJG"></a><a id="TLADG1030" name="TLADG1030"></a>
<p><b><font face="arial, helvetica, sans-serif" color="#330099">Embedded Values</font></b></p>
<p>Use the <code>@Embedded</code> annotation to persist embedded values and the <code>@ElementCollection</code> annotation for embedded collections. Because all data is stored in the XML document, no separate table (that is, <code>@CollectionTable</code>) is needed. Additionally, because embedded objects are nested in the document and do not require unique field names, the <code>@AttributeOverride</code> attribute is not needed.</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>Normally, you will not need to use the <code>@Embedded</code> annotation, since it will default correctly.</p>
<p>However, EclipseLink does not default <code>@ElementCollection</code> mappings, therefore you must include that annotation.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<a id="TLADG1031" name="TLADG1031"></a>
<p><b><font face="arial, helvetica, sans-serif" color="#330099">Relationships</font></b></p>
<p>You should use the relationship annotations (such as <code>@OneToOne</code>, <code>@ManyToOne</code>, <code>@OneToMany</code> and <code>@ManyToMany</code>) only with <em>external</em> relationships. Relationships <em>within</em> the document should use the <a href="#BABIFJJG">Embedded Values</a>.</p>
<p>EclipseLink fully supports external relationships to other documents by using a foreign key. The ID of the target object is stored in the source object's document. For a collection, a collection of IDs is stored. Use the <code>@JoinField</code> annotation to define the name of the foreign key field in the BSON document.</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>EclipseLink does not support the <code>mappedBy</code> option for relationships with non-relational databases, as the foreign keys would need to be stored on both sides.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<p>You can also define a relationship mapping by using a query. However you must use a <code>DescriptorCustomizer</code> instead of an annotation.</p>
<div class="example"><a id="TLADG1032" name="TLADG1032"></a><a id="sthref229" name="sthref229"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-2 Sample Mappings</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
@Basic
private String description;
@Basic
private double totalCost = 0;
@Embedded
private Address billingAddress;
@Embedded
private Address shippingAddress;
@ElementCollection
private List&lt;OrderLine&gt; orderLines = new ArrayList&lt;OrderLine&gt;();
@ManyToOne(fetch=FetchType.LAZY)
private Customer customer;
</pre></div>
<!-- class="example" --></div>
<!-- class="sect2" -->
<a id="BABFIJAA" name="BABFIJAA"></a><a id="TLADG1033" name="TLADG1033"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 5: Using Locking</font></h2>
<p>Locking support is dependent on the NoSQL platform. Some NoSQL platforms may offer support for optimistic version locking.</p>
<ul>
<li>
<p>Oracle NoSQL &ndash; Locking is not supported.</p>
</li>
<li>
<p>MongoDB &ndash; Version locking is supported.</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>MongoDB does not support transactions. If a lock error occurs during a transaction, any objects that have been previously written will not be rolled back.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
</li>
</ul>
<p>If the NoSQL platform does not support locking, you can use the <code>@Version</code> annotation (as shown in <a href="#BABFACAI">Example 21-3</a>) to validate objects on <code>merge()</code> operations.</p>
<div class="example"><a id="BABFACAI" name="BABFACAI"></a><a id="TLADG1034" name="TLADG1034"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-3 Using @Version</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
@Version
private long version;
...
</pre></div>
<!-- class="example" --></div>
<!-- class="sect2" -->
<a id="BABIIDED" name="BABIIDED"></a><a id="TLADG1035" name="TLADG1035"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 6: Defining Queries</font></h2>
<p>Querying in NoSQL is dependent on the NoSQL platform. Some NoSQL data-sources may support dynamic querying through their own query language, others may not support querying at all.</p>
<a id="TLADG1036" name="TLADG1036"></a>
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref230" name="sthref230"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">JPQL Queries</font></h3>
<p>The Java Persistence Query Language (JPQL) is the query language defined by JPA. JPQL can be used for reading (<code>SELECT</code>), as well as bulk updates (<code>UPDATE</code>) and deletes (<code>DELETE</code>). You can use JPQL in a <code>NamedQuery</code> (through annotations or XML) or in dynamic queries using the EntityManager <code>createQuery()</code> API.</p>
<ul>
<li>
<p>Oracle NoSQL &ndash; Supports <code>find()</code> and JPQL and Criteria by Id or with no WHERE clause.</p>
</li>
<li>
<p>MongoDB &ndash; Supports JPQL and Criteria queries, with some restrictions: joins, sub-selects, group by and certain database functions are not supported.</p>
</li>
</ul>
<div class="example"><a id="TLADG1037" name="TLADG1037"></a><a id="sthref231" name="sthref231"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-4 Oracle NoSQL JPQL Examples</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
</pre></div>
<!-- class="example" -->
<div class="example"><a id="TLADG1038" name="TLADG1038"></a><a id="sthref232" name="sthref232"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-5 MongoDB JPQL Examples</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
Query query = em.createQuery("Select o from Order o where o.totalCost &gt; 1000");
List&lt;Order&gt; orders = query.getResultList();
</pre>
<pre xml:space="preserve" class="oac_no_warn">
Query query = em.createQuery("Select o from Order o where o.description like 'Pinball%'");
List&lt;Order&gt; orders = query.getResultList();
</pre>
<pre xml:space="preserve" class="oac_no_warn">
Query query = em.createQuery("Select o from Order o join o.orderLines l where l.description = :desc");
query.setParameter("desc", "shipping");
List&lt;Order&gt; orders = query.getResultList();
</pre>
<pre xml:space="preserve" class="oac_no_warn">
Query query = em.createQuery("Select o.totalCost from Order o");
List&lt;BigDecimal&gt; orders = query.getResultList();
</pre></div>
<!-- class="example" --></div>
<!-- class="sect3" -->
<a id="TLADG1039" name="TLADG1039"></a>
<div class="sect3"><!-- infolevel="all" infotype="General" --><a id="sthref233" name="sthref233"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Native Queries</font></h3>
<p>Native SQL queries are not translated, and passed directly to the database. SQL queries can be used for advanced queries that require database specific syntax.</p>
<p>Although native SQL queries are not supported with NoSQL, some NoSQL platforms have their own, native query language. EclipseLink supports JPA native queries using that language.</p>
<ul>
<li>
<p>MongoDB &ndash; Supports JPA native queries by using the MongoDB native command language.</p>
</li>
</ul>
<div class="example"><a id="TLADG1040" name="TLADG1040"></a><a id="sthref234" name="sthref234"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-6 Oracle NoSQL Native Query</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
</pre></div>
<!-- class="example" -->
<div class="example"><a id="TLADG1041" name="TLADG1041"></a><a id="sthref235" name="sthref235"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-7 MongoDB Native Query</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
Query query = em.createNativeQuery("db.ORDER.findOne({\"_id\":\"" + oid + "\"})", Order.class);
Order order = (Order)query.getSingleResult();
</pre></div>
<!-- class="example" --></div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="BABFJIJE" name="BABFJIJE"></a><a id="TLADG1042" name="TLADG1042"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Task 7: Connecting to the Database</font></h2>
<p>EclipseLink connects to NoSQL databases through the persistence.xml file. Use the <code>&lt;eclipselink.target-database&gt;</code> property to define the specific NoSQL platform. You must also define a connection with the <code>&lt;eclipselink.nosql.connection-spec&gt;</code> property. Additional connection values (such as the <code>db</code>, <code>port</code>, and <code>host</code> can also be defined.</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>To connect to a cluster of Mongo databases, enter a comma, separated list of values for the <code>host</code> and <code>port</code>.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<div class="example"><a id="TLADG1043" name="TLADG1043"></a><a id="sthref236" name="sthref236"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-8 Oracle NoSQL persistence.xml Example</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
</pre></div>
<!-- class="example" -->
<div class="example"><a id="TLADG1044" name="TLADG1044"></a><a id="sthref237" name="sthref237"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 21-9 MongoDB persistence.xml Example</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;persistence 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 persistence_2_0.xsd" version="2.0"&gt;
&lt;persistence-unit name="acme" transaction-type="RESOURCE_LOCAL"&gt;
&lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
&lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
&lt;properties&gt;
<strong> &lt;property name="eclipselink.target-database" value="org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform"/&gt;</strong>
&lt;property name="eclipselink.nosql.connection-spec" value="org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec"/&gt;
&lt;property name="eclipselink.nosql.property.mongo.port" value="27017, 27017"/&gt;
&lt;property name="eclipselink.nosql.property.mongo.host" value="host1, host2"/&gt;
&lt;property name="eclipselink.nosql.property.mongo.db" value="acme"/&gt;
&lt;/properties&gt;
&lt;/persistence-unit&gt;
&lt;/persistence&gt;
</pre></div>
<!-- class="example" --></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="nonrelational_db001.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="nonrelational_db003.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>