Hi,
this post is related to a previous pos on the mailing list:
"JPA: adding entities to EntityManagerFactory programmatically"
I experience a NoClassDefFoundError while OpenJPA creates subclasses
for persistent classes that live in a different class loader than
OpenJPA itself.
In short, I am running in an OSGi environment (Eclipse RCP), where
one bundle (all classes in a bundle are manager by one class loader)
provides the OpenJPA libaray and the code that calls OpenJPA to
persist entities and another bundle contains entity classes.
Some details:
1.
the persistent classes are not specified at <class> tag of
persistence.xml but specified as Map before construction of EMF.
2.
The persistent classes are not enhanced at bulid-time, -javaagent is
also not activated. OpenJPA subclasses these persistent classes to
manage them.
3.
The persistent classes are loaded by different class loaders.
4.
My entities have the following inheritance hierarchy:
// Managed by class loader A
class Entity {
// get/set methods common to all entity-classes
// like id and version. Methods are JPA-annotated,
// but not the class itself
}
// Managed by class loader B
// not JPA-annotated
interface IProject {
// some get/set methods
}
// Managed by class loader B
@Entity
class Project implements IProject extends Entity {
// implemented get/set methods of IProject
// with JPA annotations
}
Would the solution be to have the ClassLoader that loads the
generated subclass consult some callback while loading classes that
are referenced by the class it is subclassing?
Or could the generated-Subclass-class-loader use the class loader of
the class it is generating the subclass for?
Thanks in advance,
Rüdiger
Stacktrace
----------
java.lang.NoClassDefFoundError: org/rhoeta/core/plan/entity/IProject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at serp.bytecode.BCClassLoader.findClass(BCClassLoader.java:50)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at serp.bytecode.BCClassLoader.findClass(BCClassLoader.java:50)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at
org.apache.openjpa.util.GeneratedClasses.loadBCClass(GeneratedClasses.java:67)
at
org.apache.openjpa.enhance.ManagedClassSubclasser.write(ManagedClassSubclasser.java:259)
at
org.apache.openjpa.enhance.ManagedClassSubclasser.access$000(ManagedClassSubclasser.java:53)
at
org.apache.openjpa.enhance.ManagedClassSubclasser$1.write(ManagedClassSubclasser.java:123)
at org.apache.openjpa.enhance.PCEnhancer.record(PCEnhancer.java:526)
at org.apache.openjpa.enhance.PCEnhancer.record(PCEnhancer.java:514)
at
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:297)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:199)
at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
at
org.rhoeta.core.internal.model.JPAModelStore.executeSql(JPAModelStore.java:95)
at
org.rhoeta.core.internal.model.JPAModelStore.doCreate(JPAModelStore.java:26)
at
org.rhoeta.core.internal.model.AbstractModelStore.create(AbstractModelStore.java:36)
at
org.rhoeta.core.plan.internal.jpastore.JPAModelStore_Test.testCreate(JPAModelStore_Test.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at
org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at
org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.eclipse.equinox.internal.app.EclipseAppContainer.callMethod(EclipseAppContainer.java:565)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:195)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:362)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:175)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)