This discussion is archived
2 Replies Latest reply: Nov 14, 2012 4:41 PM by 836522 RSS

JPA EntityManager shared across OSGi modules

836522 Newbie
Currently Being Moderated

I'd like to create an OSGi module which would act as a 'JPA master' making JPA EntityManager available to other OSGi modules. The persistence.xml would be part of this module but it would do nothing more.

I'd like to then access EntityManager from other OSGi bundles, both JARs and WARs (JAR Bundles and WAR Bundles).

I'm running on GlassFish and using EclipseLink as the JPA provider.

Any idea for best practices?

Thank you
  • 1. Re: JPA EntityManager shared across OSGi modules
    974289 Newbie
    Currently Being Moderated
    Yes, this is possible. Check out section #8.1 (Standalone Persistence Unit) of "OSGi Application Development using GlassFish Server" guide available at:

  • 2. Re: JPA EntityManager shared across OSGi modules
    836522 Newbie
    Currently Being Moderated
    Hi, thanks for the link.

    It says 'Refer to the examples to see it being used.' without a link so I read the section above that (8. JPA in OSGi Application)

    It says about some config entries in GlassFish, I enabled it but still no luck.

    Here's my /src/main/resources/META-INF/persistence.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns=""
    xsi:schemaLocation="" version="1.0">

    <persistence-unit name="cmsdbconnection">
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://"/>
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    <property name="javax.persistence.jdbc.user" value="db_user"/>
    <property name="javax.persistence.jdbc.password" value="db_user"/>
    <property name="eclipselink.ddl-generation.table-creation-suffix" value="engine=InnoDB" />
    <property name="eclipselink.ddl-generation" value="create-tables" />
    <property name="" value="=SunAS9" />


    Maven pom.xml to generate MANIFEST.MF:


    Deploying in GlassFish succeeds, but I cannot obtain the EntityManagerFactory from other OSGi bundles.

    Should that be registered as an OSGi service anyway? Because I can't see that when listing all OSGi bundles.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points