OpenJPA
  1. OpenJPA
  2. OPENJPA-1491

org.apache.openjpa.kernel.Bootstrap uses the application classloader to load OpenJPA internals

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-beta
    • Fix Version/s: 2.0.0-beta3
    • Component/s: osgi
    • Labels:
      None
    • Environment:
      OSGi

      Description

      When attempting to create an EntityManagerFactory in an OSGi environment the org.apache.openjpa.kernel.Bootstrap class attempts to instantiate a BrokerFactory using reflection. When the Bootstrap class attempts to load this class it only ever uses the ClassLoader passed in by the PersistenceUnitInfo. This means that the default broker (contained within OpenJPA) can never be loaded. The client bundle should not have to import the internals of OpenJPA to make this work, so OpenJPA should attempt to load the class using its own bundle classloader. This is the expected behaviour for an OSGi bundle.

      Additionally, the implementation uses Class.forName() which should be used carefully in an OSGi envrionment (to see why read http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html ). It should be fine here because the variant that takes a ClassLoader is used.

      The following exception is generated when OpenJPA attempts to use the application classloader to load an internal class.

      <openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static newInstance method on the named factory class "<<openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.util.UserException: The named BrokerFactory "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory" is not valid.>".
      at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:70)
      at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:145)
      at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:180)
      at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62)
      at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:227)
      at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:121)
      at org.apache.aries.jpa.container.impl.PersistenceBundleManager.modifiedBundle(PersistenceBundleManager.java:197)
      at org.apache.aries.util.tracker.MultiBundleTracker$InternalBundleTracker.modifiedBundle(MultiBundleTracker.java:108)
      at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:453)
      at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:237)
      at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)
      at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:916)
      at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:220)
      at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
      at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1350)
      at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1301)
      at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:490)
      at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:546)
      at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1098)
      at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.suspendBundle(PackageAdminImpl.java:314)
      at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.processDelta(PackageAdminImpl.java:460)
      at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.doResolveBundles(PackageAdminImpl.java:241)
      at org.eclipse.osgi.framework.internal.core.PackageAdminImpl$1.run(PackageAdminImpl.java:176)
      at java.lang.Thread.run(Thread.java:735)
      Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.persistence.ArgumentException: The named BrokerFactory "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory" is not valid.
      at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:159)
      at org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:111)
      at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:62)
      ... 23 more
      Caused by: java.lang.ClassNotFoundException: org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory
      at java.lang.Class.forName(Class.java:169)
      at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:157)
      ... 25 more

        Issue Links

          Activity

          Jörn Gersdorf made changes -
          Link This issue is related to OPENJPA-2542 [ OPENJPA-2542 ]
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Donald Woods made changes -
          Fix Version/s 2.0.0-beta3 [ 12314857 ]
          Fix Version/s 2.0.0 [ 12314019 ]
          Donald Woods made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Donald Woods made changes -
          Attachment OPENJPA-1491-trunk.patch [ 12438631 ]
          Donald Woods made changes -
          Link This issue is related to ARIES-158 [ ARIES-158 ]
          Donald Woods made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Donald Woods made changes -
          Assignee Donald Woods [ drwoods ]
          Donald Woods made changes -
          Fix Version/s 2.0.0 [ 12314019 ]
          Component/s osgi [ 12313391 ]
          Component/s integration [ 12312870 ]
          Timothy Ward made changes -
          Field Original Value New Value
          Description When attempting to create an EntityManagerFactory in an OSGi environment the org.apache.openjpa.kernel.Bootstrap class attempts to instantiate a BrokerFactory using reflection. When the Bootstrap class attempts to load this class it only ever uses the ClassLoader passed in by the PersistenceUnitInfo. This means that the default broker (contained within OpenJPA) can never be loaded. The client bundle should not have to import the internals of OpenJPA to make this work, so OpenJPA should attempt to load the class using its own bundle classloader. This is the expected behaviour for an OSGi bundle.

          Additionally, the implementation uses Class.forName() which should be avoided in an OSGi envrionment (to see why read http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html ).

          The following exception is generated when OpenJPA attempts to use the application classloader to load an internal class.

          <openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static newInstance method on the named factory class "<<openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.util.UserException: The named BrokerFactory "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory" is not valid.>".
          at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:70)
          at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:145)
          at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:180)
          at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62)
          at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:227)
          at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:121)
          at org.apache.aries.jpa.container.impl.PersistenceBundleManager.modifiedBundle(PersistenceBundleManager.java:197)
          at org.apache.aries.util.tracker.MultiBundleTracker$InternalBundleTracker.modifiedBundle(MultiBundleTracker.java:108)
          at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:453)
          at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:237)
          at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)
          at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:916)
          at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:220)
          at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
          at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1350)
          at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1301)
          at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:490)
          at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:546)
          at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1098)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.suspendBundle(PackageAdminImpl.java:314)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.processDelta(PackageAdminImpl.java:460)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.doResolveBundles(PackageAdminImpl.java:241)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl$1.run(PackageAdminImpl.java:176)
          at java.lang.Thread.run(Thread.java:735)
          Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.persistence.ArgumentException: The named BrokerFactory "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory" is not valid.
          at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:159)
          at org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:111)
          at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:62)
          ... 23 more
          Caused by: java.lang.ClassNotFoundException: org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory
          at java.lang.Class.forName(Class.java:169)
          at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:157)
          ... 25 more
          When attempting to create an EntityManagerFactory in an OSGi environment the org.apache.openjpa.kernel.Bootstrap class attempts to instantiate a BrokerFactory using reflection. When the Bootstrap class attempts to load this class it only ever uses the ClassLoader passed in by the PersistenceUnitInfo. This means that the default broker (contained within OpenJPA) can never be loaded. The client bundle should not have to import the internals of OpenJPA to make this work, so OpenJPA should attempt to load the class using its own bundle classloader. This is the expected behaviour for an OSGi bundle.

          Additionally, the implementation uses Class.forName() which should be used carefully in an OSGi envrionment (to see why read http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html ). It should be fine here because the variant that takes a ClassLoader is used.

          The following exception is generated when OpenJPA attempts to use the application classloader to load an internal class.

          <openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static newInstance method on the named factory class "<<openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.util.UserException: The named BrokerFactory "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory" is not valid.>".
          at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:70)
          at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:145)
          at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:180)
          at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62)
          at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:227)
          at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:121)
          at org.apache.aries.jpa.container.impl.PersistenceBundleManager.modifiedBundle(PersistenceBundleManager.java:197)
          at org.apache.aries.util.tracker.MultiBundleTracker$InternalBundleTracker.modifiedBundle(MultiBundleTracker.java:108)
          at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:453)
          at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:237)
          at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)
          at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:916)
          at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:220)
          at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
          at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1350)
          at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1301)
          at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:490)
          at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:546)
          at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1098)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.suspendBundle(PackageAdminImpl.java:314)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.processDelta(PackageAdminImpl.java:460)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.doResolveBundles(PackageAdminImpl.java:241)
          at org.eclipse.osgi.framework.internal.core.PackageAdminImpl$1.run(PackageAdminImpl.java:176)
          at java.lang.Thread.run(Thread.java:735)
          Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:905001 fatal user error> org.apache.openjpa.persistence.ArgumentException: The named BrokerFactory "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory" is not valid.
          at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:159)
          at org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:111)
          at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:62)
          ... 23 more
          Caused by: java.lang.ClassNotFoundException: org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory
          at java.lang.Class.forName(Class.java:169)
          at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:157)
          ... 25 more
          Timothy Ward created issue -

            People

            • Assignee:
              Donald Woods
              Reporter:
              Timothy Ward
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development