| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>2. JPA Extensions</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA User's Guide"><link rel="up" href="ref_guide_runtime.html" title="Chapter 9. Runtime Extensions"><link rel="prev" href="ref_guide_runtime.html" title="Chapter 9. Runtime Extensions"><link rel="next" href="ref_guide_locking.html" title="3. Object Locking"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2. |
| JPA Extensions |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_runtime.html">Prev</a> </td><th width="60%" align="center">Chapter 9. |
| Runtime Extensions |
| </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_locking.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ref_guide_runtime_jpa"></a>2. |
| JPA Extensions |
| </h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_emfactory">2.1. |
| OpenJPAEntityManagerFactory |
| </a></span></dt><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_em">2.2. |
| OpenJPAEntityManager |
| </a></span></dt><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_jpaquery">2.3. |
| OpenJPAQuery |
| </a></span></dt><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_jpaextent">2.4. |
| Extent |
| </a></span></dt><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_jpacache">2.5. |
| StoreCache |
| </a></span></dt><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_jpaquerycache">2.6. |
| QueryResultCache |
| </a></span></dt><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_jpafetch">2.7. |
| FetchPlan |
| </a></span></dt><dt><span class="section"><a href="ref_guide_runtime_jpa.html#ref_guide_runtime_openjpapersistence">2.8. |
| OpenJPAPersistence |
| </a></span></dt></dl></div><p> |
| The following sections outline the runtime interfaces you can use to access |
| OpenJPA-specific functionality from JPA. Each interface contains services and |
| convenience methods missing from the JPA specification. OpenJPA strives to use |
| the same naming conventions and API patterns as standard JPA methods in all |
| extensions, so that OpenJPA JDO APIs feel as much as possible like standard JPA. |
| </p><p> |
| You may have noticed the examples throughout this document using the |
| <code class="methodname">OpenJPAPersistence.cast</code> methods to cast from standard |
| JPA interfaces to OpenJPA extended interfaces. This is the recommended practice. |
| Some application server vendors may proxy OpenJPA's JPA implementation, |
| preventing a straight cast. <code class="classname">OpenJPAPersistence</code>'s |
| <code class="methodname">cast</code> methods work around these proxies. |
| </p><pre class="programlisting"> |
| public static OpenJPAEntityManagerFactory cast(EntityManagerFactory emf); |
| public static OpenJPAEntityManager cast(EntityManager em); |
| public static OpenJPAQuery cast(Query q); |
| </pre><p> |
| We provide additional information on the <code class="classname">OpenJPAPersistence |
| </code> helper <a href="ref_guide_runtime_jpa.html#ref_guide_runtime_openjpapersistence" title="2.8. OpenJPAPersistence"> |
| below</a>. |
| </p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_emfactory"></a>2.1. |
| OpenJPAEntityManagerFactory |
| </h3></div></div></div><a class="indexterm" name="d0e27373"></a><a class="indexterm" name="d0e27376"></a><p> |
| The <code class="classname">org.apache.openjpa.persistence.OpenJPAEntityManagerFactory |
| </code> interface extends the basic <code class="classname"> |
| javax.persistence.EntityManagerFactory</code> with OpenJPA-specific |
| features. The <code class="classname">OpenJPAEntityManagerFactory</code> offers APIs to |
| access the OpenJPA data and query caches and to perform other OpenJPA-specific |
| operations. See the |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/OpenJPAEntityManagerFactory.html" target="_top"> |
| interface Javadoc</a> for details. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_em"></a>2.2. |
| OpenJPAEntityManager |
| </h3></div></div></div><a class="indexterm" name="d0e27400"></a><a class="indexterm" name="d0e27403"></a><p> |
| All OpenJPA <code class="classname">EntityManager</code>s implement the |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/OpenJPAEntityManager.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.OpenJPAEntityManager</code> |
| </a> interface. This interface extends the standard <code class="classname"> |
| javax.persistence.EntityManager</code>. Just as the standard <code class="classname"> |
| EntityManager</code> is the primary window into JPA services, the |
| <code class="classname">OpenJPAEntityManager</code> is the primary window from JPA into |
| OpenJPA-specific functionality. We strongly encourage you to investigate the API |
| extensions this interface contains. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_jpaquery"></a>2.3. |
| OpenJPAQuery |
| </h3></div></div></div><a class="indexterm" name="d0e27433"></a><a class="indexterm" name="d0e27436"></a><p> |
| OpenJPA extends JPA's standard query functionality with the <code class="classname"> |
| org.apache.openjpa.persistence.OpenJPAQuery</code> interface. See its |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/OpenJPAQuery.html" target="_top">Javadoc |
| </a> for details on the convenience methods it provides. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_jpaextent"></a>2.4. |
| Extent |
| </h3></div></div></div><a class="indexterm" name="d0e27454"></a><a class="indexterm" name="d0e27457"></a><p> |
| An <code class="classname">Extent</code> is a logical view of all persistent instances |
| of a given entity class, possibly including subclasses. OpenJPA adds the |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/Extent.html" target="_top"><code class="classname"> |
| org.apache.openjpa.persistence.Extent</code></a> class to the set of |
| Java Persistence APIs. The following code illustrates iterating over all |
| instances of the <code class="classname">Magazine</code> entity, without subclasses: |
| </p><div class="example"><a name="ref_guide_runtime_jpaextentex"></a><p class="title"><b>Example 9.2. |
| Using a JPA Extent |
| </b></p><div class="example-contents"><pre class="programlisting"> |
| import org.apache.openjpa.persistence.*; |
| |
| ... |
| |
| OpenJPAEntityManager kem = OpenJPAPersistence.cast(em); |
| Extent<Magazine> mags = kem.getExtent(Magazine.class, false); |
| for (Magazine m : mags) |
| processMagazine (m); |
| </pre></div></div><br class="example-break"></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_jpacache"></a>2.5. |
| StoreCache |
| </h3></div></div></div><a class="indexterm" name="d0e27484"></a><p> |
| In addition to the <code class="classname">EntityManager</code> object cache mandated by |
| the JPA specification, OpenJPA includes a flexible datastore-level cache. You |
| can access this cache from your JPA code using the |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/StoreCache.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.StoreCache</code></a> facade. |
| <a href="ref_guide_caching.html#ref_guide_cache" title="1. Data Cache">Section 1, “ |
| Data Cache |
| ”</a> has detailed information on OpenJPA's |
| data caching system, including the <code class="classname">StoreCache</code> facade. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_jpaquerycache"></a>2.6. |
| QueryResultCache |
| </h3></div></div></div><a class="indexterm" name="d0e27505"></a><p> |
| OpenJPA can cache query results as well as persistent object data. The |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/QueryResultCache.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.QueryResultCache</code></a> |
| is an JPA-flavored facade to OpenJPA's internal query cache. See |
| <a href="ref_guide_caching.html#ref_guide_cache_query" title="1.3. Query Cache">Section 1.3, “ |
| Query Cache |
| ”</a> for details on query caching in |
| OpenJPA. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_jpafetch"></a>2.7. |
| FetchPlan |
| </h3></div></div></div><a class="indexterm" name="d0e27520"></a><a class="indexterm" name="d0e27523"></a><p> |
| Many of the aforementioned OpenJPA interfaces give you access to an <code class="classname"> |
| org.apache.openjpa.persistence.FetchPlan</code> instance. The <code class="classname"> |
| FetchPlan</code> allows you to exercise some control over how objects are |
| fetched from the datastore, including <a href="ref_guide_dbsetup_lrs.html" title="9. Large Result Sets"> |
| large result set support</a>, <a href="ref_guide_fetch.html" title="6. Fetch Groups">custom fetch |
| groups</a>, and <a href="ref_guide_locking.html" title="3. Object Locking">lock levels</a>. |
| </p><p> |
| OpenJPA goes one step further, extending <code class="classname">FetchPlan</code> with |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.JDBCFetchPlan</code></a> |
| to add additional JDBC-specific tuning methods. Unless you have customized |
| OpenJPA to use a non-relational back-end (see |
| <a href="ref_guide_enterprise_abstractstore.html" title="8. Non-Relational Stores">Section 8, “ |
| Non-Relational Stores |
| ”</a> ), all <code class="classname"> |
| FetchPlan</code>s in OpenJPA implement <code class="classname"> |
| JDBCFetchPlan</code>, so feel free to cast to this interface. |
| </p><p> |
| Fetch plans pass on from parent components to child components. The <code class="classname"> |
| EntityManagerFactory</code> settings (via your configuration properties) |
| for things like the fetch size, result set type, and custom fetch groups are |
| passed on to the fetch plan of the <code class="classname">EntityManager</code>s it |
| produces. The settings of each <code class="classname">EntityManager</code>, in turn, |
| are passed on to each <code class="classname">Query</code> and <code class="classname">Extent |
| </code> it returns. Note that the opposite, however, is not true. Modifying |
| the fetch plan of a <code class="classname">Query</code> or <code class="classname">Extent |
| </code> does not affect the <code class="classname">EntityManager</code>'s |
| configuration. Likewise, modifying an <code class="classname">EntityManager</code>'s |
| configuration does not affect the <code class="classname"> EntityManagerFactory</code>. |
| </p><p> |
| <a href="ref_guide_fetch.html" title="6. Fetch Groups">Section 6, “ |
| Fetch Groups |
| ”</a> includes examples using <code class="classname"> |
| FetchPlan</code>s. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="ref_guide_runtime_openjpapersistence"></a>2.8. |
| OpenJPAPersistence |
| </h3></div></div></div><a class="indexterm" name="d0e27605"></a><p> |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/OpenJPAPersistence.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.OpenJPAPersistence</code></a> |
| is a static helper class that adds OpenJPA-specific utility methods to |
| <code class="classname">javax.persistence.Persistence</code>. |
| </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_runtime.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_runtime.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_locking.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 9. |
| Runtime Extensions |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 3. |
| Object Locking |
| </td></tr></table></div></body></html> |