glassfish
  1. glassfish
  2. GLASSFISH-14134

[JPA] Allow JPA in Java SE mode from OSGi context

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.1_ms07
    • Component/s: OSGi-JavaEE
    • Labels:
      None
    • Environment:

      Operating System: Linux
      Platform: Linux

    • Issuezilla Id:
      14,134

      Description

      Hi *,

      I just stumbled across a problem:

      I have an OSGi bundle that contains an activator which then calls some class
      which itself tries to get an EntityManagerFactory programmatically using the
      standard JPA utility class javax.persistence.Persistence:

      emf = Persistence.createEntityManagerFactory("jpa-test");

      The JPA unit is declared like this (persistence.xml):

      <persistence-unit name="jpa-test" transaction-type="JTA">
      <jta-data-source>jdbc/__default</jta-data-source>
      </persistence-unit>

      As the container should find an appropriate persistence provider using the
      services mechanisms I don't specify one here.

      The error I get is:

      INFO: Error while starting bundle:
      file:/srv/servers/glassfish/v31-b25/glassfish3/glassfish/domains/domain1/autodeploy/bundles/osgi.jpa-1.0-SNAPSHOT.jar:
      org.osgi.framework.BundleException: Activator start error in bundle
      org.glassfish.test.osgi.jpa [287].
      INFO: org.osgi.framework.BundleException: Activator start error in bundle
      org.glassfish.test.osgi.jpa [287].
      INFO: at org.apache.felix.framework.Felix.activateBundle(Felix.java:1869)
      INFO: at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
      INFO: at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:922)
      INFO: at
      org.apache.felix.fileinstall.internal.DirectoryWatcher.start(DirectoryWatcher.java:1136)
      INFO: at
      org.apache.felix.fileinstall.internal.DirectoryWatcher.start(DirectoryWatcher.java:1122)
      INFO: at
      org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1115)
      INFO: at
      org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:433)
      INFO: at
      org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:241)
      INFO: Caused by: javax.persistence.PersistenceException: No Persistence provider
      for EntityManager named jpa-test
      INFO: at
      javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
      INFO: at
      javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
      INFO: at
      org.glassfish.test.osgi.jpa.EMFactoryInitializer.init(EMFactoryInitializer.java:21)
      INFO: at org.glassfish.test.osgi.jpa.Activator.start(Activator.java:13)
      INFO: at
      org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633)
      INFO: at org.apache.felix.framework.Felix.activateBundle(Felix.java:1822)
      INFO: ... 7 more

      I also tried to overcome this problem with specifying the provider in the
      persistence.xml file but without any change. Also a change to RESOURCE_LOCAL and
      <non-jta-data-source> does not make any difference.

      Is this manual way of initializing JPA currently unsupported within OSGi in
      GlassFish?

      I tested promoted builds b24 and b25.

      The main reason I want to do this is because I'm currently about to bring Apache
      ODE nicely into the OSGi world without much impact but as long as EJB's are
      registered in JNDI after the OSGi activator started the bundle successfully I'm
      stuck to the programmatic initialization of JPA.

      Need some help here. In one and/or another way.

      P.S.: I'll attach a very simple test case.

        Activity

        Hide
        chaoslayer added a comment -

        Are there no integration tests that cover JPA deployments?

        I would think that a project like glassfish should have thousands of test cases that are run before each of the promoted builds.

        However do you expect any negative side effects of this JPA resolver method? I mean in my case the situation would that I want to use this method for initialization of ODE (JavaSE mode resolver) but I will definitely have a lot of other OSGi bundles that use standard JavaEE injection techniques to get their Entitymanager inside various SLSBs.

        Show
        chaoslayer added a comment - Are there no integration tests that cover JPA deployments? I would think that a project like glassfish should have thousands of test cases that are run before each of the promoted builds. However do you expect any negative side effects of this JPA resolver method? I mean in my case the situation would that I want to use this method for initialization of ODE (JavaSE mode resolver) but I will definitely have a lot of other OSGi bundles that use standard JavaEE injection techniques to get their Entitymanager inside various SLSBs.
        Hide
        Sanjeeb Sahoo added a comment -

        There are plenty of tests in GlassFish that test JPA deployment.

        No, I don't expect any negative effect of the new resolver. I have tried it in normal EE apps as well. In fact, it fixes a couple of nasty bugs in the default resolver that's defined in the reference implementation. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=331094 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=331098. The new resolver I wrote does not have such bugs at least.

        Show
        Sanjeeb Sahoo added a comment - There are plenty of tests in GlassFish that test JPA deployment. No, I don't expect any negative effect of the new resolver. I have tried it in normal EE apps as well. In fact, it fixes a couple of nasty bugs in the default resolver that's defined in the reference implementation. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=331094 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=331098 . The new resolver I wrote does not have such bugs at least.
        Hide
        chaoslayer added a comment -

        Perfect.

        Once again thanks a lot for this!

        Show
        chaoslayer added a comment - Perfect. Once again thanks a lot for this!
        Hide
        Sanjeeb Sahoo added a comment -

        Just committed:

        Please note the name change once again. It is now called osgi-jpa-extension. The property names have also been changed. So, if you have applied earlier attached patches, roll them back, get a new glassfish build and set the following property to true in felix or equinox config file ( the property is set to false by default, as this is an extension):

        org.glassfish.osgjpa.extension.useHybridPersistenceProviderResolver=true

        ss141213@Sahoo:/space/ss141213/WS/gf/v3$ svn commit -F msg osgi-javaee/ packager/glassfish-jpa/ osgi-platforms/
        Adding osgi-javaee/osgi-jpa-extension
        Adding osgi-javaee/osgi-jpa-extension/osgi.bundle
        Adding osgi-javaee/osgi-jpa-extension/pom.xml
        Adding osgi-javaee/osgi-jpa-extension/src
        Adding osgi-javaee/osgi-jpa-extension/src/main
        Adding osgi-javaee/osgi-jpa-extension/src/main/java
        Adding osgi-javaee/osgi-jpa-extension/src/main/java/org
        Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish
        Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa
        Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension
        Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension/HybridPersistenceProviderResolver.java
        Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension/JPAStartupService.java
        Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension/OSGiJPAExtnBundleActivator.java
        Sending osgi-javaee/pom.xml
        Sending osgi-platforms/equinox/src/main/resources/glassfish/osgi/equinox/configuration/config.ini
        Sending osgi-platforms/felix/src/main/resources/glassfish/osgi/felix/conf/config.properties
        Sending packager/glassfish-jpa/pom.xml
        Transmitting file data .........
        Committed revision 43268.

        Show
        Sanjeeb Sahoo added a comment - Just committed: Please note the name change once again. It is now called osgi-jpa-extension. The property names have also been changed. So, if you have applied earlier attached patches, roll them back, get a new glassfish build and set the following property to true in felix or equinox config file ( the property is set to false by default, as this is an extension): org.glassfish.osgjpa.extension.useHybridPersistenceProviderResolver=true ss141213@Sahoo:/space/ss141213/WS/gf/v3$ svn commit -F msg osgi-javaee/ packager/glassfish-jpa/ osgi-platforms/ Adding osgi-javaee/osgi-jpa-extension Adding osgi-javaee/osgi-jpa-extension/osgi.bundle Adding osgi-javaee/osgi-jpa-extension/pom.xml Adding osgi-javaee/osgi-jpa-extension/src Adding osgi-javaee/osgi-jpa-extension/src/main Adding osgi-javaee/osgi-jpa-extension/src/main/java Adding osgi-javaee/osgi-jpa-extension/src/main/java/org Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension/HybridPersistenceProviderResolver.java Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension/JPAStartupService.java Adding osgi-javaee/osgi-jpa-extension/src/main/java/org/glassfish/osgijpa/extension/OSGiJPAExtnBundleActivator.java Sending osgi-javaee/pom.xml Sending osgi-platforms/equinox/src/main/resources/glassfish/osgi/equinox/configuration/config.ini Sending osgi-platforms/felix/src/main/resources/glassfish/osgi/felix/conf/config.properties Sending packager/glassfish-jpa/pom.xml Transmitting file data ......... Committed revision 43268.
        Hide
        Sanjeeb Sahoo added a comment -

        Updated the synopsys

        Show
        Sanjeeb Sahoo added a comment - Updated the synopsys

          People

          • Assignee:
            Sanjeeb Sahoo
            Reporter:
            chaoslayer
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: