openjpa-dev mailing list archives

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


Joshua Shrader closed OPENJPA-1962.

    Resolution: Invalid

Sorry...  this isn't a bug.  It was a problem with the classloader and JNDI, as explained

For future reference, my chunk of code really needs to be
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        URLClassLoader loader = new URLClassLoader(new URL[]{new URL(URL_OF_JAR)}, this.getClass().getClassLoader());
        try {
            Class<Runnable> clazz = (Class<Runnable>) loader.loadClass("test.CustomerTestRunner");
        } finally {

> openjpa uses application ClassLoader for resolving BrokerFactory (revisited again)
> ----------------------------------------------------------------------------------
>                 Key: OPENJPA-1962
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.1.0
>            Reporter: Joshua Shrader
>              Labels: classloader, url
> 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");
> clazz.newInstance().run();
> 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$
> 	at Method)
> 	at
> 	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