| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>9. Mapping Extensions</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.2 User's Guide"><link rel="up" href="ref_guide_mapping.html" title="Chapter 7. Mapping"><link rel="prev" href="ref_guide_mapping_limits.html" title="8. Mapping Limitations"><link rel="next" href="ref_guide_mapping_custom.html" title="10. Custom Mappings"></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">9. |
| Mapping Extensions |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_mapping_limits.html">Prev</a> </td><th width="60%" align="center">Chapter 7. |
| Mapping |
| </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_mapping_custom.html">Next</a></td></tr></table><hr></div><div class="section" title="9. Mapping Extensions"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="ref_guide_mapping_ext">9. |
| Mapping Extensions |
| </h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ref_guide_mapping_ext.html#ref_guide_mapping_ext_cls">9.1. |
| Class Extensions |
| </a></span></dt><dd><dl><dt><span class="section"><a href="ref_guide_mapping_ext.html#subclass-fetch-mode">9.1.1. |
| Subclass Fetch Mode |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#class-strategy">9.1.2. |
| Strategy |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#discriminator-strategy">9.1.3. |
| Discriminator Strategy |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#version-strategy">9.1.4. |
| Version Strategy |
| </a></span></dt></dl></dd><dt><span class="section"><a href="ref_guide_mapping_ext.html#ref_guide_mapping_ext_field">9.2. |
| Field Extensions |
| </a></span></dt><dd><dl><dt><span class="section"><a href="ref_guide_mapping_ext.html#eager-fetch-mode">9.2.1. |
| Eager Fetch Mode |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#nonpolymorphic">9.2.2. |
| Nonpolymorphic |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#class-criteria">9.2.3. |
| Class Criteria |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#strategy">9.2.4. |
| Strategy |
| </a></span></dt></dl></dd></dl></div> |
| |
| <p> |
| Mapping extensions allow you to access OpenJPA-specific functionality from your |
| mappings. Note that all extensions below are specific to mappings. If you store |
| your mappings separately from your persistence metadata, these extensions must |
| be specified along with the mapping information, not the persistence metadata |
| information. |
| </p> |
| <div class="section" title="9.1. Class Extensions"><div class="titlepage"><div><div><h3 class="title" id="ref_guide_mapping_ext_cls">9.1. |
| Class Extensions |
| </h3></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ref_guide_mapping_ext.html#subclass-fetch-mode">9.1.1. |
| Subclass Fetch Mode |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#class-strategy">9.1.2. |
| Strategy |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#discriminator-strategy">9.1.3. |
| Discriminator Strategy |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#version-strategy">9.1.4. |
| Version Strategy |
| </a></span></dt></dl></div> |
| |
| <p> |
| OpenJPA recognizes the following class extensions. |
| </p> |
| <div class="section" title="9.1.1. Subclass Fetch Mode"><div class="titlepage"><div><div><h4 class="title" id="subclass-fetch-mode">9.1.1. |
| Subclass Fetch Mode |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14780"></a> |
| <p> |
| This extension specifies how to eagerly fetch subclass state. It overrides the |
| global <a class="link" href="ref_guide_conf_jdbc.html#openjpa.jdbc.SubclassFetchMode" title="6.16. openjpa.jdbc.SubclassFetchMode"><code class="literal"> |
| openjpa.jdbc.SubclassFetchMode</code></a> property. Set the OpenJPA |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/SubclassFetchMode.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.SubclassFetchMode</code> |
| </a> annotation to a value from the |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/FetchMode.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.FetchMode</code> |
| </a> enum: <code class="literal">JOIN</code>, <code class="literal">PARALLEL</code>, or |
| <code class="literal">NONE</code>. See <a class="xref" href="ref_guide_perfpack_eager.html" title="8. Eager Fetching">Section 8, “ |
| Eager Fetching |
| ”</a> |
| for a discussion of eager fetching. |
| </p> |
| </div> |
| <div class="section" title="9.1.2. Strategy"><div class="titlepage"><div><div><h4 class="title" id="class-strategy">9.1.2. |
| Strategy |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14798"></a> |
| <p> |
| The <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/Strategy.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.Strategy</code></a> |
| class annotation allows you to specify a custom mapping strategy for your class. |
| See <a class="xref" href="ref_guide_mapping_custom.html" title="10. Custom Mappings">Section 10, “ |
| Custom Mappings |
| ”</a> for information on custom |
| mappings. |
| </p> |
| </div> |
| <div class="section" title="9.1.3. Discriminator Strategy"><div class="titlepage"><div><div><h4 class="title" id="discriminator-strategy">9.1.3. |
| Discriminator Strategy |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14809"></a> |
| <p> |
| The |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/DiscriminatorStrategy.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.DiscriminatorStrategy</code> |
| </a> class annotation allows you to specify a custom discriminator strategy. |
| See <a class="xref" href="ref_guide_mapping_custom.html" title="10. Custom Mappings">Section 10, “ |
| Custom Mappings |
| ”</a> for information on custom |
| mappings. |
| </p> |
| </div> |
| <div class="section" title="9.1.4. Version Strategy"><div class="titlepage"><div><div><h4 class="title" id="version-strategy">9.1.4. |
| Version Strategy |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14820"></a> |
| <p> |
| The |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/VersionStrategy.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.VersionStrategy</code> |
| </a> class annotation allows you to specify a custom version strategy. See |
| <a class="xref" href="ref_guide_mapping_custom.html" title="10. Custom Mappings">Section 10, “ |
| Custom Mappings |
| ”</a> for information on custom |
| mappings. |
| </p> |
| </div> |
| </div> |
| <div class="section" title="9.2. Field Extensions"><div class="titlepage"><div><div><h3 class="title" id="ref_guide_mapping_ext_field">9.2. |
| Field Extensions |
| </h3></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ref_guide_mapping_ext.html#eager-fetch-mode">9.2.1. |
| Eager Fetch Mode |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#nonpolymorphic">9.2.2. |
| Nonpolymorphic |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#class-criteria">9.2.3. |
| Class Criteria |
| </a></span></dt><dt><span class="section"><a href="ref_guide_mapping_ext.html#strategy">9.2.4. |
| Strategy |
| </a></span></dt></dl></div> |
| |
| <p> |
| OpenJPA recognizes the following field extensions. |
| </p> |
| <div class="section" title="9.2.1. Eager Fetch Mode"><div class="titlepage"><div><div><h4 class="title" id="eager-fetch-mode">9.2.1. |
| Eager Fetch Mode |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14834"></a> |
| <p> |
| This extension specifies how to eagerly fetch related objects. It overrides the |
| global <a class="link" href="ref_guide_conf_jdbc.html#openjpa.jdbc.EagerFetchMode" title="6.4. openjpa.jdbc.EagerFetchMode"><code class="literal"> |
| openjpa.jdbc.EagerFetchMode</code></a> property. Set the OpenJPA |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/EagerFetchMode.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.EagerFetchMode</code> |
| </a> annotation to a value from the |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/FetchMode.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.FetchMode</code> |
| </a> enum: <code class="literal">JOIN</code>, <code class="literal">PARALLEL</code>, or |
| <code class="literal">NONE</code>. See <a class="xref" href="ref_guide_perfpack_eager.html" title="8. Eager Fetching">Section 8, “ |
| Eager Fetching |
| ”</a> |
| for a discussion of eager fetching. |
| </p> |
| </div> |
| <div class="section" title="9.2.2. Nonpolymorphic"><div class="titlepage"><div><div><h4 class="title" id="nonpolymorphic">9.2.2. |
| Nonpolymorphic |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14852"></a> |
| <p> |
| All fields in Java are polymorphic. If you declare a field of type <code class="literal">T |
| </code>, you can assign any subclass of <code class="literal">T</code> to the field as |
| well. This is very convenient, but can make relation traversal very inefficient |
| under some inheritance strategies. It can even make querying across the field |
| impossible. Often, you know that certain fields do not need to be entirely |
| polymorphic. By telling OpenJPA about such fields, you can improve the |
| efficiency of your relations. |
| </p> |
| <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3> |
| <p> |
| OpenJPA also includes the <code class="literal">type</code> metadata extension for |
| narrowing the declared type of a field. See <a class="xref" href="ref_guide_meta_ext.html#type" title="4.2.6. Type">Section 4.2.6, “ |
| Type |
| ”</a>. |
| </p> |
| </div> |
| <p> |
| OpenJPA defines the following extensions for nonpolymorphic values: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/Nonpolymorphic.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.Nonpolymorphic</code> |
| </a> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/ElementNonpolymorphic.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.ElementNonpolymorphic</code> |
| </a> |
| </p> |
| </li></ul></div> |
| <p> |
| The value of these extensions is a constant from the |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/NonpolymorphicType.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.NonpolymorphicType</code> |
| </a> enumeration. The default value, <code class="literal">EXACT</code>, indicates |
| that the relation will always be of the exact declared type. A value of |
| <code class="literal">JOINABLE</code>, on the other hand, means that the relation might |
| be to any joinable subclass of the declared type. This value only excludes |
| table-per-class subclasses. |
| </p> |
| </div> |
| <div class="section" title="9.2.3. Class Criteria"><div class="titlepage"><div><div><h4 class="title" id="class-criteria">9.2.3. |
| Class Criteria |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14880"></a> |
| <a class="indexterm" name="d5e14885"></a> |
| <p> |
| This family of boolean extensions determines whether OpenJPA will use the |
| expected class of related objects as criteria in the SQL it issues to load a |
| relation field. Typically, this is not needed. The foreign key values uniquely |
| identify the record for the related object. Under some rare mappings, however, |
| you may need to consider both foreign key values and the expected class of the |
| related object - for example, if you have an inverse relation that shares the |
| foreign key with another inverse relation to an object of a different subclass. |
| In these cases, set the proper class criteria extension to <code class="literal">true |
| </code> to force OpenJPA to append class criteria to its select SQL. |
| </p> |
| <p> |
| OpenJPA defines the following class criteria annotations for field relations and |
| array or collection element relations, respectively: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/ClassCriteria.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.ClassCriteria</code></a> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/ElementClassCriteria.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.ElementClassCriteria</code> |
| </a> |
| </p> |
| </li></ul></div> |
| </div> |
| <div class="section" title="9.2.4. Strategy"><div class="titlepage"><div><div><h4 class="title" id="strategy">9.2.4. |
| Strategy |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e14902"></a> |
| <p> |
| OpenJPA's |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/jdbc/Strategy.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.jdbc.Strategy</code></a> |
| extension allows you to specify a custom mapping |
| strategy or value handler for a field. See |
| <a class="xref" href="ref_guide_mapping_custom.html" title="10. Custom Mappings">Section 10, “ |
| Custom Mappings |
| ”</a> for information on custom |
| mappings. |
| </p> |
| </div> |
| </div> |
| </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_mapping_limits.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_mapping.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_mapping_custom.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">8. |
| Mapping Limitations |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 10. |
| Custom Mappings |
| </td></tr></table></div></body></html> |