openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joshua Shrader (JIRA)" <>
Subject [jira] Created: (OPENJPA-1962) openjpa uses application ClassLoader for resolving BrokerFactory (revisited again)
Date Fri, 18 Mar 2011 00:42:29 GMT
openjpa uses application ClassLoader for resolving BrokerFactory (revisited again)

                 Key: OPENJPA-1962
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 2.1.0
            Reporter: Joshua Shrader

Previous references to the "The named BrokerFactory 'org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory'
is not valid." exception thrown in Bootstrap.getFactoryClass() have applied to OSGi environments.
 We're having the same problem, although we are not using OSGi.

Our environment may be a bit non-standard, but I think it is (or should be) a valid use case.
 It is also possible that I'm missing a classloader subtlety, but I don't think so.

We developed a very simple application that uses openjpa to insert a couple items into a database.
 We jar the application, including the openjpa-all-2.1.0.jar, and deploy it on a webserver.
 We then use a URLClassLoader from a host program to access a class from this jar.  For example,
in the host program:

URLClassLoader loader = new URLClassLoader(new URL[]{new URL(URL_OF_JAR)}, this.getClass().getClassLoader());
Class<Runnable> clazz = (Class<Runnable>) loader.loadClass("test.CustomerTestRunner");

The application accessing the jar on the webserver knows nothing about openjpa.  The test.CustomerTestRunner
uses openjpa to create and persist a couple entities.  This causes the error:
Exception in thread "main" javax.persistence.PersistenceException: Explicit persistence provider
error(s) occurred for "testjpa" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl
from provider: org.apache.openjpa.persistence.PersistenceProviderImpl

which is ultimately caused by

Caused by: java.lang.ClassNotFoundException: org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(
	at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(
	... 11 more

Putting the jar directly on the classpath fixes the problem, but defeats the purpose.

This message is automatically generated by JIRA.
For more information on JIRA, see:

View raw message