Author: hthomann
Date: Thu Apr 18 17:08:36 2013
New Revision: 1469452
URL: http://svn.apache.org/r1469452
Log:
OPENJPA-2027: Metamodel genereated at runtime expects ListAttribute for all
arrays - not just PersistentCollections. Back-ported Mike Dick's trunk changes
to 2.1.x; made Compatibility property default to true.
Modified:
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java
openjpa/branches/2.1.x/openjpa-project/src/doc/manual/migration_considerations.xml
Modified:
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java?rev=1469452&r1=1469451&r2=1469452&view=diff
==============================================================================
---
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
(original)
+++
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
Thu Apr 18 17:08:36 2013
@@ -72,7 +72,7 @@ public class Compatibility {
private boolean _resetFlushFlagForCascadePersist = false;//OPENJPA-2051
private boolean _overrideContextClassloader = false; //OPENJPA-1993
private boolean _filterPCRegistryClasses = false; // OPENJPA-2288
-
+ private boolean _useListAttributeForArrays = true;
/**
* Whether to require exact identity value types when creating object
@@ -655,5 +655,31 @@ public class Compatibility {
public void setFilterPCRegistryClasses(boolean bool) {
_filterPCRegistryClasses = bool;
}
+
+ /**
+ * This property can be used to allow OpenJPA to use ListAttributes for
all types of Arrays, not just those with the
+ *
+ * @PersistentCollection annotation. If the canonical metamodel classes
were generated in an early version of
+ * OpenJPA (e.g. 2.0.0, 2.0.1, or 2.1.0) it is
recommended to set this property to true.
+ * @since 2.1.2
+ * @return true if OpenJPA will use ListAttributes for <b>all</b> arrays,
false if OpenJPA will use ListAttributes
+ * for <b>only</b> arrays which use the @PersistentCollection
annotation.
+ */
+ public boolean getUseListAttributeForArrays() {
+ return _useListAttributeForArrays;
+ }
+
+ /**
+ * This property can be used to allow OpenJPA to use ListAttributes for
all types of Arrays, not just those with the
+ *
+ * @PersistentCollection annotation. If the canonical metamodel classes
were generated in an early version of
+ * OpenJPA (e.g. 2.0.0, 2.0.1, or 2.1.0) it is
recommended to set this property to true.
+ * @since 2.1.2
+ * @param useListAttribute
+ * whether OpenJPA will use ListAttributes for all arrays.
+ */
+ public void setUseListAttributeForArrays(boolean useListAttribute ) {
+ _useListAttributeForArrays = useListAttribute;
+ }
}
Modified:
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=1469452&r1=1469451&r2=1469452&view=diff
==============================================================================
---
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++
openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Thu Apr 18 17:08:36 2013
@@ -220,6 +220,8 @@ public class FieldMetaData
private boolean _isElementCollection = false;
private int _associationType;
+ private boolean _persistentCollection = false;
+
/**
* Constructor.
*
@@ -2234,5 +2236,13 @@ public class FieldMetaData
public void setAssociationType(int type) {
_associationType = type;
}
+
+ public boolean isPersistentCollection() {
+ return _persistentCollection;
+ }
+
+ public void setPersistentCollection(boolean persistentCollection) {
+ _persistentCollection = persistentCollection;
+ }
}
Modified:
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=1469452&r1=1469451&r2=1469452&view=diff
==============================================================================
---
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Thu Apr 18 17:08:36 2013
@@ -1634,6 +1634,8 @@ public class AnnotationPersistenceMetaDa
throw new MetaDataException(_loc.get("bad-meta-anno", fmd,
"PersistentCollection"));
+ fmd.setPersistentCollection(true);
+
if (!StringUtils.isEmpty(anno.mappedBy()))
fmd.setMappedBy(anno.mappedBy());
fmd.setInDefaultFetchGroup(anno.fetch() == FetchType.EAGER);
Modified:
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java?rev=1469452&r1=1469451&r2=1469452&view=diff
==============================================================================
---
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java
(original)
+++
openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java
Thu Apr 18 17:08:36 2013
@@ -39,6 +39,7 @@ import javax.persistence.metamodel.SetAt
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.PluralAttribute.CollectionType;
+import org.apache.openjpa.conf.Compatibility;
import org.apache.openjpa.kernel.Filters;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.ClassMetaData;
@@ -157,7 +158,13 @@ public abstract class AbstractManagedTyp
attrs.add(new Members.SingularAttributeImpl(this, f));
break;
case JavaTypes.ARRAY:
- attrs.add(new Members.ListAttributeImpl(this, f));
+ Compatibility compat =
meta.getRepository().getConfiguration().getCompatibilityInstance();
+ if(compat.getUseListAttributeForArrays() ||
f.isPersistentCollection()) {
+ attrs.add(new Members.ListAttributeImpl(this, f));
+ }
+ else {
+ attrs.add(new Members.SingularAttributeImpl(this, f));
+ }
break;
case JavaTypes.COLLECTION:
switch
(MetamodelImpl.categorizeCollection(f.getDeclaredType())) {
Modified:
openjpa/branches/2.1.x/openjpa-project/src/doc/manual/migration_considerations.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-project/src/doc/manual/migration_considerations.xml?rev=1469452&r1=1469451&r2=1469452&view=diff
==============================================================================
---
openjpa/branches/2.1.x/openjpa-project/src/doc/manual/migration_considerations.xml
(original)
+++
openjpa/branches/2.1.x/openjpa-project/src/doc/manual/migration_considerations.xml
Thu Apr 18 17:08:36 2013
@@ -353,6 +353,32 @@
has no effect in 2.1.x and later releases and any
occurrence of it should be removed.
</para>
</section>
+ <section id="jpa_2.2_metamodelArrays">
+ <title>
+ MetaModel attributes for Arrays
+ </title>
+ <!-- See OPENJPA-2025 for details. -->
+ <para>
+ OpenJPA's MetaModel implementation generates a
ListAttribute for every array. This behavior is correct if the array
+ is annotated as a PersistentCollection, but not correct
for un-annotated arrays (e.g. byte[], char[]). This behavior has been corrected
+ so that arrays which are not stored as
PersistentCollections will use a SingularAttribute instead of a ListAttribute.
This correction
+ is only enabled via a compatibility property (described
below).
+ </para>
+ <para>
+ If youre application uses the MetaModel API and your
entities contain arrays of any of the following types: byte[], Byte[], char[],
Character[] and
+ do not use the @PersistentCollection annotation with those
fields you will need to do the following:
+ <itemizedlist>
+ <listitem>
+ <para> Regenerate the canonical metamodel
classes</para>
+ </listitem>
+ <listitem>
+ <para> Set the Compatibility property
<literal>UseListAttributeForArrays</literal> to <literal>false</literal>in
persistence.xml
+ <programlisting> <property
name="openjpa.Compatibility"
value="UseListAttributeForArrays=false"/></programlisting>
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </section>
</section>
</section>
<section id="jpa_2.1">