| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>4. Metadata Extensions</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.4 User's Guide"><link rel="up" href="ref_guide_meta.html" title="Chapter 6. Metadata"><link rel="prev" href="ref_guide_meta_jpa.html" title="3. Additional JPA Metadata"><link rel="next" href="ref_guide_mapping.html" title="Chapter 7. Mapping"></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">4. |
| Metadata Extensions |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_meta_jpa.html">Prev</a> </td><th width="60%" align="center">Chapter 6. |
| Metadata |
| </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_mapping.html">Next</a></td></tr></table><hr></div><div class="section" id="ref_guide_meta_ext"><div class="titlepage"><div><div><h2 class="title" style="clear: both">4. |
| Metadata Extensions |
| </h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="ref_guide_meta_ext.html#ref_guide_meta_class">4.1. |
| Class Extensions |
| </a></span></dt><dd><dl><dt><span class="section"><a href="ref_guide_meta_ext.html#fetch-groups">4.1.1. |
| Fetch Groups |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#data-cache">4.1.2. |
| Data Cache |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#detached-state-field">4.1.3. |
| Detached State |
| </a></span></dt></dl></dd><dt><span class="section"><a href="ref_guide_meta_ext.html#ref_guide_meta_field">4.2. |
| Field Extensions |
| </a></span></dt><dd><dl><dt><span class="section"><a href="ref_guide_meta_ext.html#dependent">4.2.1. |
| Dependent |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#load-fetch-group">4.2.2. |
| Load Fetch Group |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#lrs">4.2.3. |
| LRS |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#inverse-logical">4.2.4. |
| Inverse-Logical |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#read-only">4.2.5. |
| Read-Only |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#type">4.2.6. |
| Type |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#externalizer">4.2.7. |
| Externalizer |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#factory">4.2.8. |
| Factory |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#external-values">4.2.9. |
| External Values |
| </a></span></dt></dl></dd><dt><span class="section"><a href="ref_guide_meta_ext.html#ref_guide_meta_example">4.3. |
| Example |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#ref_guide_meta_xml">4.4. |
| XML extensions |
| </a></span></dt></dl></div> |
| |
| <a class="indexterm" name="d5e13327"></a> |
| <p> |
| OpenJPA extends standard metadata to allow you to access advanced OpenJPA |
| functionality. This section covers persistence metadata extensions; we discuss |
| mapping metadata extensions in <a class="xref" href="ref_guide_mapping_ext.html" title="9. Mapping Extensions">Section 9, “ |
| Mapping Extensions |
| ”</a>. |
| All metadata extensions are optional; OpenJPA will rely on its defaults when no |
| explicit data is provided. |
| </p> |
| <div class="section" id="ref_guide_meta_class"><div class="titlepage"><div><div><h3 class="title">4.1. |
| Class Extensions |
| </h3></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="ref_guide_meta_ext.html#fetch-groups">4.1.1. |
| Fetch Groups |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#data-cache">4.1.2. |
| Data Cache |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#detached-state-field">4.1.3. |
| Detached State |
| </a></span></dt></dl></div> |
| |
| <p> |
| OpenJPA recognizes the following class extensions: |
| </p> |
| <div class="section" id="fetch-groups"><div class="titlepage"><div><div><h4 class="title">4.1.1. |
| Fetch Groups |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13337"></a> |
| <p> |
| The <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/FetchGroups.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.FetchGroups</code></a> and |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/FetchGroup.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.FetchGroup</code></a> |
| annotations allow you to define fetch groups in your JPA entities. |
| <a class="xref" href="ref_guide_fetch.html" title="7. Fetch Groups">Section 7, “ |
| Fetch Groups |
| ”</a> discusses OpenJPA's support for fetch |
| groups in general; see <a class="xref" href="ref_guide_fetch.html#ref_guide_fetch_custom" title="7.1. Custom Fetch Groups">Section 7.1, “ |
| Custom Fetch Groups |
| ”</a> for how to |
| use these annotations in particular. |
| </p> |
| </div> |
| <div class="section" id="data-cache"><div class="titlepage"><div><div><h4 class="title">4.1.2. |
| Data Cache |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13351"></a> |
| <p> |
| <a class="xref" href="ref_guide_caching.html#ref_guide_cache" title="1. Data Cache">Section 1, “ |
| Data Cache |
| ”</a> examines caching in OpenJPA. Metadata |
| extensions allow individual classes to override system caching defaults. |
| </p> |
| <p> |
| OpenJPA defines the |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/DataCache.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.DataCache</code></a> |
| annotation for caching information. This annotation has the following |
| properties: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> |
| <p> |
| <code class="literal">boolean enabled</code>: Whether to cache data for instances of the |
| class. Defaults to <code class="literal">true</code> for base classes, or the superclass |
| value for subclasses. If you set this property to <code class="literal">false</code>, all |
| other properties are ignored. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">int timeout</code>: The number of milliseconds data for the class |
| remains valid. Use -1 for no timeout. Defaults to the |
| <a class="link" href="ref_guide_conf_openjpa.html#openjpa.DataCacheTimeout" title="5.29. openjpa.DataCacheTimeout"><code class="literal"> openjpa.DataCacheTimeout |
| </code></a> property value. |
| </p> |
| </li></ul></div> |
| </div> |
| <div class="section" id="detached-state-field"><div class="titlepage"><div><div><h4 class="title">4.1.3. |
| Detached State |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13374"></a> |
| <p> |
| The OpenJPA <a class="link" href="ref_guide_pc_enhance.html" title="2. Enhancement">enhancer</a> may add a |
| synthetic field to detachable classes to hold detached state (see |
| <a class="xref" href="ref_guide_remote.html#ref_guide_detach_graph" title="1.3. Defining the Detached Object Graph">Section 1.3, “ |
| Defining the Detached Object Graph |
| ”</a> for details). You can instead |
| declare your own detached state field or suppress the creation of a detached |
| state field altogether. In the latter case, your class must not use |
| <a class="link" href="ref_guide_pc_oid.html" title="4. Object Identity">datastore identity</a>, and should declare |
| a version field to detect optimistic concurrency errors during detached |
| modifications. |
| </p> |
| <p> |
| OpenJPA defines the |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/DetachedState.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.DetachedState</code></a> |
| annotation for controlling detached state. When used to annotate a class, |
| <code class="classname">DetachedState</code> recognizes the following properties: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> |
| <p> |
| <code class="literal">boolean enabled</code>: Set to false to suppress the use of |
| detached state. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">String fieldName</code>: Use this property to declare your own |
| detached state field. The field must be of type <code class="classname">Object</code>. |
| Typically this property is only used if the field is inherited from a |
| non-persisted superclass. If the field is declared in your entity class, you |
| will typically annotate the field directly, as described below. |
| </p> |
| </li></ul></div> |
| <p> |
| If you declare your own detached state field, you can annotate that field with |
| <code class="classname">DetachedState</code> directly, rather than placing the |
| annotation at the class level and using the <code class="literal">fieldName</code> |
| property. When placed on a field, <code class="classname">DetachedState</code> acts as a |
| marker annotation; it does not recognize any properties. Your annotated field |
| must be of type <code class="classname">Object</code>. |
| </p> |
| </div> |
| </div> |
| <div class="section" id="ref_guide_meta_field"><div class="titlepage"><div><div><h3 class="title">4.2. |
| Field Extensions |
| </h3></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="ref_guide_meta_ext.html#dependent">4.2.1. |
| Dependent |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#load-fetch-group">4.2.2. |
| Load Fetch Group |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#lrs">4.2.3. |
| LRS |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#inverse-logical">4.2.4. |
| Inverse-Logical |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#read-only">4.2.5. |
| Read-Only |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#type">4.2.6. |
| Type |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#externalizer">4.2.7. |
| Externalizer |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#factory">4.2.8. |
| Factory |
| </a></span></dt><dt><span class="section"><a href="ref_guide_meta_ext.html#external-values">4.2.9. |
| External Values |
| </a></span></dt></dl></div> |
| |
| <p> |
| OpenJPA recognizes the following field extensions: |
| </p> |
| <div class="section" id="dependent"><div class="titlepage"><div><div><h4 class="title">4.2.1. |
| Dependent |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13405"></a> |
| <p> |
| In a <span class="emphasis"><em>dependent</em></span> relation, the referenced object is deleted |
| whenever the owning object is deleted, or whenever the relation is severed by |
| nulling or resetting the owning field. For example, if the <code class="literal"> |
| Magazine.coverArticle</code> field is marked dependent, then setting |
| <code class="literal">Magazine.coverArticle</code> to a new <code class="classname">Article</code> |
| instance will automatically delete the old <code class="classname">Article</code> stored |
| in the field. Similarly, deleting a <code class="classname">Magazine</code> object will |
| automatically delete its current cover <code class="classname">Article</code>. (This |
| latter processing is analogous to using JPA's CascadeType.REMOVE functionality |
| as described in <a class="xref" href="jpa_overview_meta_field.html#jpa_overview_meta_cascade" title="2.9.1. Cascade Type">Section 2.9.1, “ |
| Cascade Type |
| ”</a>.) You can |
| prevent an orphaned dependent object from being automatically deleted by |
| assigning it to another relation in the same transaction. |
| </p> |
| <p> |
| OpenJPA offers a family of marker annotations to denote dependent relations in |
| JPA entities: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/Dependent.html" target="_top"> |
| <code class="classname"> org.apache.openjpa.persistence.Dependent</code></a>: Marks |
| a direct relation as dependent. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/ElementDependent.html" target="_top"> |
| <code class="classname"> org.apache.openjpa.persistence.ElementDependent</code></a> |
| : Marks the entity elements of a collection, array, or map field as dependent. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/KeyDependent.html" target="_top"> |
| <code class="classname"> org.apache.openjpa.persistence.KeyDependent</code></a>: |
| Marks the key entities in a map field as dependent. |
| </p> |
| </li></ul></div> |
| </div> |
| <div class="section" id="load-fetch-group"><div class="titlepage"><div><div><h4 class="title">4.2.2. |
| Load Fetch Group |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13434"></a> |
| <a class="indexterm" name="d5e13438"></a> |
| <p> |
| The <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/LoadFetchGroup.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.LoadFetchGroup</code></a> |
| annotation specifies a field's load fetch group. |
| <a class="xref" href="ref_guide_fetch.html" title="7. Fetch Groups">Section 7, “ |
| Fetch Groups |
| ”</a> discusses OpenJPA's support for fetch groups |
| in general; see <a class="xref" href="ref_guide_fetch.html#ref_guide_fetch_custom" title="7.1. Custom Fetch Groups">Section 7.1, “ |
| Custom Fetch Groups |
| ”</a> for how to use this |
| annotation in particular. |
| </p> |
| </div> |
| <div class="section" id="lrs"><div class="titlepage"><div><div><h4 class="title">4.2.3. |
| LRS |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13448"></a> |
| <p> |
| This boolean extension, denoted by the OpenJPA |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/LRS.html" target="_top"><code class="classname"> |
| org.apache.openjpa.persistence.LRS</code></a> annotation, |
| indicates that a field should use OpenJPA's special large result set collection |
| or map proxies. A complete description of large result set proxies is available |
| in <a class="xref" href="ref_guide_pc_scos.html#ref_guide_pc_scos_proxy_lrs" title="6.4.2. Large Result Set Proxies">Section 6.4.2, “ |
| Large Result Set Proxies |
| ”</a>. |
| </p> |
| </div> |
| <div class="section" id="inverse-logical"><div class="titlepage"><div><div><h4 class="title">4.2.4. |
| Inverse-Logical |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13459"></a> |
| <p> |
| This extension names the inverse field in a logical bidirectional relation. |
| To create a logical bidirectional relation in OpenJPA, use the |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/InverseLogical.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.InverseLogical</code></a> |
| annotation. We discuss logical bidirectional relations and this |
| extension in detail in <a class="xref" href="ref_guide_inverses.html" title="5. Managed Inverses">Section 5, “ |
| Managed Inverses |
| ”</a>. |
| </p> |
| </div> |
| <div class="section" id="read-only"><div class="titlepage"><div><div><h4 class="title">4.2.5. |
| Read-Only |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13470"></a> |
| <a class="indexterm" name="d5e13475"></a> |
| <p> |
| The read-only extension makes a field unwritable. The extension only applies to |
| existing persistent objects; new object fields are always writeable. |
| </p> |
| <p> |
| To mark a field read-only in JPA metadata, set the |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/ReadOnly.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.ReadOnly</code></a> |
| annotation to an |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/UpdateAction.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.UpdateAction</code></a> enum |
| value. The <code class="classname">UpdateAction</code> enum includes: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> |
| <p> |
| <code class="literal">UpdateAction.IGNORE</code>: Updates to the field are completely |
| ignored. The field is not considered dirty. The new value will not even get |
| stored in the OpenJPA <a class="link" href="ref_guide_caching.html#ref_guide_cache" title="1. Data Cache">data cache</a>. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">UpdateAction.RESTRICT</code>: Any attempt to change the field will |
| result in an immediate exception. |
| </p> |
| </li></ul></div> |
| </div> |
| <div class="section" id="type"><div class="titlepage"><div><div><h4 class="title">4.2.6. |
| Type |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13495"></a> |
| <p> |
| OpenJPA has three levels of support for relations: |
| </p> |
| <div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"> |
| <p> |
| Relations that hold a reference to an object of a concrete persistent class are |
| supported by storing the primary key values of the related instance in the |
| database. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| Relations that hold a reference to an object of an unknown persistent class are |
| supported by storing the stringified identity value of the related instance. |
| This level of support does not allow queries across the relation. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| Relations that hold an unknown object or interface. The only way to support |
| these relations is to serialize their value to the database. This does not allow |
| you to query the field, and is not very efficient. |
| </p> |
| </li></ol></div> |
| <p> |
| Clearly, when you declare a field's type to be another persistence-capable |
| class, OpenJPA uses level 1 support. By default, OpenJPA assumes that any |
| interface-typed fields you declare will be implemented only by other persistent |
| classes, and assigns interfaces level 2 support. The exception to this rule is |
| the <code class="classname">java.io.Serializable</code> interface. If you declare a |
| field to be of type <code class="classname">Serializable</code>, OpenJPA lumps it |
| together with <code class="classname">java.lang.Object</code> fields and other |
| non-interface, unrecognized field types, which are all assigned level 3 support. |
| </p> |
| <p> |
| With OpenJPA's type family of metadata extensions, you can control the level of |
| support given to your unknown/interface-typed fields. Setting the value of this |
| extension to <code class="classname">Entity</code> indicates that the |
| field value will always be some persistent object, and gives level 2 support. |
| Setting the value of this extension to the class of a concrete persistent type |
| is even better; it gives you level 1 support (just as if you had declared your |
| field to be of that type in the first place). Setting this extension to |
| <code class="classname">Object</code> uses level 3 support. This is useful when you have |
| an interface relation that may <span class="bold"><strong>not</strong></span> hold other |
| persistent objects (recall that OpenJPA assumes interface fields will always |
| hold persistent instances by default). |
| </p> |
| <p> |
| This extension is also used with OpenJPA's externalization feature, described in |
| <a class="xref" href="ref_guide_pc_scos.html#ref_guide_pc_extern" title="6.5. Externalization">Section 6.5, “ |
| Externalization |
| ”</a>. |
| </p> |
| <p> |
| OpenJPA defines the following type annotations for field values, collection, |
| array, and map elements, and map keys, respectively: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/Type.html" target="_top"><code class="classname"> |
| org.apache.openjpa.persistence.Type</code></a> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/ElementType.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.ElementType</code></a> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/KeyType.html" target="_top"><code class="classname"> |
| org.apache.openjpa.persistence.KeyType</code></a> |
| </p> |
| </li></ul></div> |
| </div> |
| <div class="section" id="externalizer"><div class="titlepage"><div><div><h4 class="title">4.2.7. |
| Externalizer |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13534"></a> |
| <p> |
| The OpenJPA |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/Externalizer.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.Externalizer</code></a> |
| annotation names a method to transform a field value into a value of |
| another type. See <a class="xref" href="ref_guide_pc_scos.html#ref_guide_pc_extern" title="6.5. Externalization">Section 6.5, “ |
| Externalization |
| ”</a> for details. |
| </p> |
| </div> |
| <div class="section" id="factory"><div class="titlepage"><div><div><h4 class="title">4.2.8. |
| Factory |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13545"></a> |
| <p> |
| The OpenJPA |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/Factory.html" target="_top"><code class="classname"> |
| org.apache.openjpa.persistence.Factory</code></a> annotation |
| names a method to re-create a field value from its externalized form. See |
| <a class="xref" href="ref_guide_pc_scos.html#ref_guide_pc_extern" title="6.5. Externalization">Section 6.5, “ |
| Externalization |
| ”</a> for details. |
| </p> |
| </div> |
| <div class="section" id="external-values"><div class="titlepage"><div><div><h4 class="title">4.2.9. |
| External Values |
| </h4></div></div></div> |
| |
| <a class="indexterm" name="d5e13556"></a> |
| <p> |
| The OpenJPA |
| <a class="ulink" href="../javadoc/org/apache/openjpa/persistence/ExternalValues.html" target="_top"> |
| <code class="classname">org.apache.openjpa.persistence.ExternalValues</code></a> |
| annotation declares values for transformation of simple fields to |
| different constant values in the datastore. See |
| <a class="xref" href="ref_guide_pc_scos.html#ref_guide_pc_extern_values" title="6.5.1. External Values">Section 6.5.1, “ |
| External Values |
| ”</a> for details. |
| </p> |
| </div> |
| </div> |
| <div class="section" id="ref_guide_meta_example"><div class="titlepage"><div><div><h3 class="title">4.3. |
| Example |
| </h3></div></div></div> |
| |
| <p> |
| The following example shows you how to specify extensions in metadata. |
| </p> |
| <div class="example" id="ref_guide_metaex"><p class="title"><b>Example 6.4. |
| OpenJPA Metadata Extensions |
| </b></p><div class="example-contents"> |
| |
| <pre class="programlisting"> |
| import org.apache.openjpa.persistence.*; |
| |
| @Entity |
| @DataCache(enabled=false) |
| public class Magazine |
| { |
| @ManyToMany |
| @LRS |
| private Collection<Subscriber> subscribers; |
| |
| @ExternalValues({"true=1", "false=2"}) |
| @Type(int.class) |
| private boolean weekly; |
| |
| ... |
| } |
| </pre> |
| </div></div><br class="example-break"> |
| </div> |
| <div class="section" id="ref_guide_meta_xml"><div class="titlepage"><div><div><h3 class="title">4.4. |
| XML extensions |
| </h3></div></div></div> |
| |
| <p> |
| OpenJPA has extended the JPA 2.0 schema to include elements and attributes corresponding |
| to OpenJPA extended metadata and mapping annotations. The schema are contained in 2 |
| files: <a class="ulink" href="http://openjpa.apache.org/builds/latest/docs/schema/extendable/extendable-orm.xsd" target="_top"> |
| extendable-orm.xsd</a> and |
| <a class="ulink" href="http://openjpa.apache.org/builds/latest/docs/schema/openjpa-orm.xsd" target="_top">openjpa-orm.xsd</a>. |
| The extendable-orm.xsd file provides copies of some of the JPA 2.0 schema elements with additional schema to make it |
| extendable. |
| The openjpa-orm.xsd file extends the extendable-orm.xsd with OpenJPA specific elements and attributes representing |
| OpenJPA annotations. Currently, only a subset of annotations have actually been implemented, and some of those |
| have been partially tested. The current status can be found by comments in the |
| <a class="ulink" href="http://openjpa.apache.org/builds/latest/docs/schema/openjpa-orm.xsd" target="_top">openjpa-orm.xsd</a> |
| schema file. |
| </p> |
| <p> |
| In order to use the OpenJPA extensions in your mapping file you must include the namespaces for these 2 new |
| schemas as well as for the schema for JPA 2.0, as shown in the following example: |
| </p> |
| <div class="example" id="ref_guide_schema_ex"><p class="title"><b>Example 6.5. |
| OpenJPA Schema Extensions |
| </b></p><div class="example-contents"> |
| |
| <pre class="programlisting"> |
| <entity-mappings xmlns="http://www.apache.org/openjpa/ns/orm/extendable" |
| xmlns:openjpa="http://www.apache.org/openjpa/ns/orm" |
| xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| version="2.0"> |
| |
| <entity class="org.apache.openjpa.persistence.jdbc.annotations.MultiColumnVersionPC" |
| metadata-complete="true"> |
| <table name="MCV"/> |
| <attributes> |
| <id name="id"> |
| <orm:generated-value/> |
| </id> |
| <basic name="id"/> |
| <basic name="name"/> |
| </attributes> |
| <openjpa:entity version-strategy="version-numbers"> |
| <openjpa:version-columns> |
| <openjpa:version-column name="v1"/> |
| <openjpa:version-column name="v2"/> |
| <openjpa:version-column name="v3" |
| column-definition="FLOAT" |
| scale="3" |
| precision="10"/> |
| </openjpa:version-columns> |
| </openjpa:entity> |
| </entity> |
| |
| </entity-mappings> |
| |
| </pre> |
| </div></div><br class="example-break"> |
| </div> |
| </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_meta_jpa.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_meta.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_mapping.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. |
| Additional JPA Metadata |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 7. |
| Mapping |
| </td></tr></table></div></body></html> |