Index: openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java =================================================================== --- openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java (revision 556794) +++ openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java (working copy) @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; @@ -27,6 +28,7 @@ import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; +import org.apache.openjpa.util.InternalException; import org.apache.openjpa.util.UserException; /** @@ -44,6 +46,19 @@ // map of pc classes to meta structs; weak so the VM can GC classes private static final Map _metas = new ConcurrentReferenceHashMap (ReferenceMap.WEAK, ReferenceMap.HARD); + + private static final Map _primitives = new HashMap(); + static { + _primitives.put("boolean", boolean.class); + _primitives.put("byte", byte.class); + _primitives.put("char", char.class); + _primitives.put("double", double.class); + _primitives.put("float", float.class); + _primitives.put("int", int.class); + _primitives.put("long", long.class); + _primitives.put("short", short.class); + } + // register class listeners private static final Collection _listeners = new LinkedList(); @@ -88,8 +103,35 @@ */ public static Class[] getFieldTypes(Class pcClass) { Meta meta = getMeta(pcClass); - return meta.fieldTypes; + String[] fieldTypes = meta.fieldTypes; + Class[] result = new Class[fieldTypes.length]; + ClassLoader fieldLoader = pcClass.getClassLoader(); + for (int i=0; iPersistenceCapable @@ -98,7 +140,8 @@ */ public static Class getPersistentSuperclass(Class pcClass) { Meta meta = getMeta(pcClass); - return meta.pcSuper; + return getClassForName(meta.pcSuper, pcClass.getClassLoader(), + "super class of " + pcClass.getName()); } /** @@ -110,7 +153,7 @@ Meta meta = getMeta(pcClass); return (meta.pc == null) ? null : meta.pc.pcNewInstance(sm, clear); } - + /** * Create a new instance of the class and assign its state manager and oid. * The new instance has its flags set to LOAD_REQUIRED. @@ -238,22 +281,27 @@ /** * This is a helper class to manage metadata per persistence-capable class. + * The type information is maintained as class names rather than Class + * to allow garbage collection. */ private static class Meta { public final PersistenceCapable pc; public final String[] fieldNames; - public final Class[] fieldTypes; - public final Class pcSuper; + public final String[] fieldTypes; + public final String pcSuper; public final String alias; public Meta(PersistenceCapable pc, String[] fieldNames, Class[] fieldTypes, Class pcSuper, String alias) { this.pc = pc; this.fieldNames = fieldNames; - this.fieldTypes = fieldTypes; - this.pcSuper = pcSuper; + this.pcSuper = (pcSuper == null) ? null : pcSuper.getName(); this.alias = alias; + this.fieldTypes = new String[fieldTypes.length]; + for (int i=0; i