OpenJPA
  1. OpenJPA
  2. OPENJPA-1918

MetaDataRepository.preload() ignores class loader returned by PersistenceUnitInfo.getClassLoader()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.1, 2.1.0, 2.2.0
    • Fix Version/s: 2.1.0, 2.2.0
    • Component/s: kernel
    • Labels:
      None
    • Environment:
      apache-karaf-2.1.0, openjdk-1.6.0b20

      Description

      We are using openjpa inside an OSGi container together with

      openjpa.MetaDataRepository" value="Preload=true"

      We pass the appliation class loeader as part of our PersistenceUnitInfo implementation by returning it from PersistenceUnitInfo.getClassLoader().

      However, the code in MetaDataRepository.preload() only uses the context class loader and not the class loader from PersistenceUnitInfo, which leades to ClassNotFoundExpcetions like mentioned at the end of this report.

      A fix might be quite easily establihed by appending the return value of PersistenceUnitInfo.getClassLoader() to the list of claas loaders participating in the MultiClassLoader set up in

      MetaDataRepository.java:310ff

      In the meanwhile, we are additionally setting our classloader as context loader during the creation of the EntityManagerFactory by PersistenceProvider.createContainerEntityManagerFactory(), but a fix in MetaDatRepository.preload() is highly appreciated.

      TIA for fixing this,

      Wolfgang

      Stack trace:

      org.osgi.service.blueprint.container.ComponentDefinitionException: Error when instantiating bean entityManagerFactory of class null
      at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:233)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:726)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:147)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:624)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:315)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:213)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.6.0_20]
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.6.0_20]
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.6.0_20]
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:165)[:1.6.0_20]
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:266)[:1.6.0_20]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)[:1.6.0_20]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)[:1.6.0_20]
      at java.lang.Thread.run(Thread.java:636)[:1.6.0_20]
      Caused by: <openjpa-2.0.1-r422266:989424 fatal user error> org.apache.openjpa.persistence.ArgumentException: Unexpected error during early loading of entity metadata during initialization. See nested stacktrace for details.
      at org.apache.openjpa.meta.MetaDataRepository.preload(MetaDataRepository.java:331)
      at org.apache.openjpa.persistence.PersistenceProviderImpl.preloadMetaDataRepository(PersistenceProviderImpl.java:280)
      at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:211)
      at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_20]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.6.0_20]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.6.0_20]
      at java.lang.reflect.Method.invoke(Method.java:616)[:1.6.0_20]
      at org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe$JdkProxyFactory$1.invoke(AbstractServiceReferenceRecipe.java:632)
      at $Proxy67.createContainerEntityManagerFactory(Unknown Source)
      at org.clazzes.util.jpa.provider.EntityManagerFactoryFactory.newEntityManagerFactory(EntityManagerFactoryFactory.java:108)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_20]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.6.0_20]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.6.0_20]
      at java.lang.reflect.Method.invoke(Method.java:616)[:1.6.0_20]
      at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:221)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:844)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:231)[7:org.apache.aries.blueprint:0.3.0.incubating-SNAPSHOT]
      ... 15 more
      Caused by: java.security.PrivilegedActionException: java.lang.ClassNotFoundException: org.clazzes.fancymail.server.entities.EMail
      at java.security.AccessController.doPrivileged(Native Method)[:1.6.0_20]
      at org.apache.openjpa.meta.MetaDataRepository.preload(MetaDataRepository.java:326)
      ... 32 more
      Caused by: java.lang.ClassNotFoundException: org.clazzes.fancymail.server.entities.EMail
      at org.apache.openjpa.lib.util.MultiClassLoader.findClass(MultiClassLoader.java:216)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)[:1.6.0_20]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)[:1.6.0_20]
      at java.lang.Class.forName0(Native Method)[:1.6.0_20]
      at java.lang.Class.forName(Class.java:264)[:1.6.0_20]
      at org.apache.openjpa.lib.util.J2DoPrivHelper$4.run(J2DoPrivHelper.java:233)
      at org.apache.openjpa.lib.util.J2DoPrivHelper$4.run(J2DoPrivHelper.java:231)
      ... 34 more

      1. OPENJPA-1918.2.patch
        4 kB
        Rick Curtis
      2. openjpa-1918.1-trunk.jar
        57 kB
        Rick Curtis

        Activity

        Hide
        Rick Curtis added a comment -

        Would you be able to try out a patch for 2.1.x or trunk?

        Show
        Rick Curtis added a comment - Would you be able to try out a patch for 2.1.x or trunk?
        Hide
        Rick Curtis added a comment -

        Please give this patch a try. It should work on 2.1.x and trunk.... it might even work for 2.0.x.

        Show
        Rick Curtis added a comment - Please give this patch a try. It should work on 2.1.x and trunk.... it might even work for 2.0.x.
        Hide
        Wolfgang Glas added a comment -

        Rick,

        ThX for having alook at my issue, I sure will try out any patch. I've now checked out the 2.1.x branch an I will hopefully be able to compile the stuff.

        Right now it looks like I have a good mileage

        I had to increase my ulimit for the maximal number of open files in order to get teh enhance test up and running, ithis ok ? :-/

        And 2.1.0 as a target milestone looks quite OK for me.

        Best regards, Wolfgang

        Show
        Wolfgang Glas added a comment - Rick, ThX for having alook at my issue, I sure will try out any patch. I've now checked out the 2.1.x branch an I will hopefully be able to compile the stuff. Right now it looks like I have a good mileage I had to increase my ulimit for the maximal number of open files in order to get teh enhance test up and running, ithis ok ? :-/ And 2.1.0 as a target milestone looks quite OK for me. Best regards, Wolfgang
        Hide
        Wolfgang Glas added a comment -

        Rick, could you please supply the patch as an output of 'svn diff' or 'diff -u', so I can apply it to my working copy of the 2.1.x branch ?

        TIA, Wolfgang

        Show
        Wolfgang Glas added a comment - Rick, could you please supply the patch as an output of 'svn diff' or 'diff -u', so I can apply it to my working copy of the 2.1.x branch ? TIA, Wolfgang
        Hide
        Rick Curtis added a comment -

        Wolfgang -

        Take a peek inside the jar... the patch is there.

        Thanks,
        Rick

        Show
        Rick Curtis added a comment - Wolfgang - Take a peek inside the jar... the patch is there. Thanks, Rick
        Hide
        Wolfgang Glas added a comment -

        Fixed by Rick's patch, works like acharm for me

        Show
        Wolfgang Glas added a comment - Fixed by Rick's patch, works like acharm for me
        Hide
        Wolfgang Glas added a comment -

        Rick, Thanks for your patch, forgot to mention, that I applis it to 2.1.x branch an now I don't need the context class laoder workaround anymore.

        Show
        Wolfgang Glas added a comment - Rick, Thanks for your patch, forgot to mention, that I applis it to 2.1.x branch an now I don't need the context class laoder workaround anymore.
        Hide
        Rick Curtis added a comment -

        Wolfgang -

        Can I have you also try with this patch? I re-ordered the classloaders because I'm quite paranoid that I'm going to break others with this change. Please confirm that this also fixes your problem.

        Thanks so much!

        Rick

        Show
        Rick Curtis added a comment - Wolfgang - Can I have you also try with this patch? I re-ordered the classloaders because I'm quite paranoid that I'm going to break others with this change. Please confirm that this also fixes your problem. Thanks so much! Rick
        Hide
        Wolfgang Glas added a comment -

        Second version works for me, too

        In apache-karaf the standard context class laoder is a boot delegation class loader from teh framework essentially exposing system and framework classes. The bundle class loader ait atop of this boot delgation class loader, so the order in your patch should not cause majot headaches insode apache-karaf.

        Sorry for setting the issue to resolved so fast :-/

        Wolfgang

        Show
        Wolfgang Glas added a comment - Second version works for me, too In apache-karaf the standard context class laoder is a boot delegation class loader from teh framework essentially exposing system and framework classes. The bundle class loader ait atop of this boot delgation class loader, so the order in your patch should not cause majot headaches insode apache-karaf. Sorry for setting the issue to resolved so fast :-/ Wolfgang
        Hide
        Albert Lee added a comment -

        Close issue in preparation for 2.2.0 release.

        Show
        Albert Lee added a comment - Close issue in preparation for 2.2.0 release.

          People

          • Assignee:
            Rick Curtis
            Reporter:
            Wolfgang Glas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development