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_dev
    • 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

        chaoslayer created issue -
        kenaiadmin made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 14134 45738
        Sanjeeb Sahoo made changes -
        Attachment entities1-osgi.jar [ 23572 ]
        Attachment changes.zip [ 23573 ]
        Sanjeeb Sahoo made changes -
        Attachment changes2.zip [ 23600 ]
        Sanjeeb Sahoo made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Sanjeeb Sahoo made changes -
        Summary [JPA] "No Persistence provider" in a non-EJB/-CDI OSGi bundle [JPA] Allow JPA in Java SE mode from OSGi context
        Joe Di Pol made changes -
        Fix Version/s 3.1_dev [ 17780 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: