Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2542

Using custom openjpa.BrokerFactory not working in OSGi due to ClassLoader

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.0, 2.4.0
    • Fix Version/s: 2.4.0
    • Component/s: osgi
    • Labels:
      None
    • Environment:
      JBoss Fuse 6.1, Apache Aries JPA 1.0.1.redhat-610379

      Description

      For reasons discussed on the openjpa-user MailingList I need to use a custom BrokerFactory in an OSGi environment.

      My custom BrokerFactory is obviously in my own OSGi bundle, not in the official OpenJPA bundle. Now, due to OPENJPA-1491 org.apache.openjpa.kernel.Bootstrap (in connection with {{org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceUnitInfo, Map) and org.apache.openjpa.persistence.osgi.PersistenceActivator.getBundleClassLoader()), my BrokerFactories can only live in the official OpenJPA bundle, so that my custom BrokerFactory is not found.

      In my opinion it would be better if org.apache.openjpa.persistence.osgi.PersistenceActivator.getBundleClassLoader() would return a ClassLoader not only delegating to openjpa´s bundle but in addition (as a fallback) to the PersistenceUnitInfo´s bundle.

      That way one would be able to use arbitrary BrokerFactories by importing them if required to the bundle where persistence.xml is defined.

        Issue Links

          Activity

          Hide
          curtisr7 Rick Curtis added a comment -

          See if the attached patch will resolve the problem you've encountered.

          Thanks,
          Rick

          Show
          curtisr7 Rick Curtis added a comment - See if the attached patch will resolve the problem you've encountered. Thanks, Rick
          Hide
          j0xaf Jörn Gersdorf added a comment -

          Hi Rick,

          wow, that´s been fast. Thank you. I´ve tested the patch under JBoss Fuse 6.1 / Karaf 2.3.0 and it´s working fine, no more ClassNotFoundExceptions.

          Best regards,
          Jörn

          Show
          j0xaf Jörn Gersdorf added a comment - Hi Rick, wow, that´s been fast. Thank you. I´ve tested the patch under JBoss Fuse 6.1 / Karaf 2.3.0 and it´s working fine, no more ClassNotFoundExceptions. Best regards, Jörn
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 1644414 from Rick Curtis in branch 'openjpa/trunk'
          [ https://svn.apache.org/r1644414 ]

          OPENJPA-2542: Use bundle classloader AND PersistenceUnitInfo classloader when creating a BrokerFactory.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 1644414 from Rick Curtis in branch 'openjpa/trunk' [ https://svn.apache.org/r1644414 ] OPENJPA-2542 : Use bundle classloader AND PersistenceUnitInfo classloader when creating a BrokerFactory.
          Hide
          curtisr7 Rick Curtis added a comment -

          Committed revision 1644414 to trunk.

          Show
          curtisr7 Rick Curtis added a comment - Committed revision 1644414 to trunk.
          Hide
          ancoron Ancoron Luciferis added a comment -

          Just as a side-note: I've also encountered this issue but I was working around it by providing the custom BrokerFactory and related classes inside an OSGi fragment bundle, attaching to the OpenJPA one.

          That way, it's automatically part of the OpenJPA ClassLoader.

          Nevertheless, having official support for application-level BrokerFactory customization is really nice, thank you.

          Show
          ancoron Ancoron Luciferis added a comment - Just as a side-note: I've also encountered this issue but I was working around it by providing the custom BrokerFactory and related classes inside an OSGi fragment bundle, attaching to the OpenJPA one. That way, it's automatically part of the OpenJPA ClassLoader. Nevertheless, having official support for application-level BrokerFactory customization is really nice, thank you.

            People

            • Assignee:
              curtisr7 Rick Curtis
              Reporter:
              j0xaf Jörn Gersdorf
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development