diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java index 9e4cb5726..bdb2c61d6 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java @@ -658,8 +658,7 @@ public class StateManagerImpl boolean loaded) { int idx = _meta.getExtraFieldDataIndex(field); if (idx == -1) - throw new InternalException(String.valueOf(_meta.getField - (field))); + throw new InternalException(String.valueOf(_meta.getField(field))); Object old = (_fieldImpl == null) ? null : _fieldImpl[idx]; if (data != null) { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java index a1fe176d8..32db27635 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; import java.io.OutputStream; import java.io.Serializable; @@ -28,6 +29,7 @@ import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.kernel.StoreContext; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.MultiClassLoader; /** * Helper class to serialize and deserialize persistent objects, @@ -74,7 +76,7 @@ public class Serialization { public static Object deserialize(InputStream in, StoreContext ctx) { try { if (ctx == null) - return new ObjectInputStream(in).readObject(); + return new ClassResolvingObjectInputStream(in).readObject(); return new PersistentObjectInputStream(in, ctx).readObject(); } catch (Exception e) { throw new StoreException(e); @@ -106,11 +108,34 @@ public class Serialization { } } + private static class ClassResolvingObjectInputStream + extends ObjectInputStream { + + public ClassResolvingObjectInputStream(InputStream delegate) + throws IOException { + super(delegate); + } + + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException { + MultiClassLoader loader = new MultiClassLoader(); + addContextClassLoaders(loader); + loader.addClassLoader(getClass().getClassLoader()); + loader.addClassLoader(MultiClassLoader.SYSTEM_LOADER); + return Class.forName(desc.getName(), true, loader); + } + + protected void addContextClassLoaders(MultiClassLoader loader) { + loader.addClassLoader(Thread.currentThread(). + getContextClassLoader()); + } + } + /** * Object input stream that replaces oids with their objects. */ private static class PersistentObjectInputStream - extends ObjectInputStream { + extends ClassResolvingObjectInputStream { private final StoreContext _ctx; @@ -126,6 +151,11 @@ public class Serialization { enableResolveObject(true); } + protected void addContextClassLoaders(MultiClassLoader loader) { + super.addContextClassLoaders(loader); + loader.addClassLoader(_ctx.getClassLoader()); + } + protected Object resolveObject(Object obj) { if (!(obj instanceof ObjectIdMarker)) return obj;