summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMythily Parthasarathy2013-05-01 16:25:10 (EDT)
committer David Minsky2013-05-01 16:25:10 (EDT)
commitdaf436213d7321ca1f5a83fa197cbe1112313758 (patch)
tree19f066f065c59650c97ed2010aa1654265ee4e37
parentcafc1dd74c14c4444539e78cd969063eafcc2863 (diff)
downloadeclipselink.runtime-daf436213d7321ca1f5a83fa197cbe1112313758.zip
eclipselink.runtime-daf436213d7321ca1f5a83fa197cbe1112313758.tar.gz
eclipselink.runtime-daf436213d7321ca1f5a83fa197cbe1112313758.tar.bz2
Fix for bug 402064 - NullPointerException in MappedSuperClassTypeImpl when initializing metamodel
- Changes to MappedSuperclassTypeImpl getMemberFromInheritingType() and ManagedTypeImpl initialize() to avoid a potential NPE during Metamodel initialization Testing: JPA LRG on Oracle & MySQL Submitted fix from: Mythily Parthasarathy <mythily.parthasarathy@oracle.com> Signed-off-by: David Minsky <david.minsky@oracle.com>, Guy Pelletier <guy.pelletier@oracle.com>
-rw-r--r--jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java8
-rw-r--r--jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java16
2 files changed, 20 insertions, 4 deletions
diff --git a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java
index 1fc58bc..fc65957 100644
--- a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java
+++ b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java
@@ -1122,6 +1122,14 @@ public abstract class ManagedTypeImpl<X> extends TypeImpl<X> implements ManagedT
* abstract superclass of List, Set and Map (with Map not really a Collection).
* We therefore need to treat Collection here as a peer of the other "collections" while also treating it as a non-instantiated superclass.
*/
+
+ // this could have been initialized earlier if it is an inheriting subclass of a MappedSuperclassType
+ // See MappedSuperclassType.getMemberFromInheritingType()
+ if (null != this.members) {
+ //this is already initialized
+ return;
+ }
+
this.members = new HashMap<String, Attribute<X, ?>>();
// Get and process all mappings on the relationalDescriptor
for (DatabaseMapping mapping : getDescriptor().getMappings()) {
diff --git a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java
index 42970ca..7595be2 100644
--- a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java
+++ b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java
@@ -102,10 +102,18 @@ public class MappedSuperclassTypeImpl<X> extends IdentifiableTypeImpl<X> impleme
public AttributeImpl getMemberFromInheritingType(String name) {
AttributeImpl inheritedAttribute = null;
// search the inheriting types map for an attribute matching the attribute name
- for(IdentifiableTypeImpl inheritingType : inheritingIdentifiableTypes.values()) {
- if(inheritingType.getMembers().containsKey(name)) {
- inheritedAttribute = (AttributeImpl)inheritingType.getAttribute(name);
- break;
+ for(IdentifiableTypeImpl inheritingType : inheritingIdentifiableTypes.values()) {
+ //Entity types are initialized before MappedSuperclass types. However, it is possible that the inheriting MappedSuperclass is not yet initialized.
+ Map inheritingTypeMembers = inheritingType.getMembers();
+ if ((null == inheritingTypeMembers) && inheritingType.isMappedSuperclass()) {
+ //not initialized
+ ((ManagedTypeImpl) inheritingType).initialize();
+ inheritingTypeMembers = inheritingType.getMembers();
+ }
+
+ if(inheritingTypeMembers.containsKey(name)) {
+ inheritedAttribute = (AttributeImpl)inheritingType.getAttribute(name);
+ break;
}
}
// we will return a null attribute in the case that a MappedSuperclass has no implementing entities