users@glassfish.java.net

Re: JPA/OSGi Bundle

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Wed, 08 Jun 2011 08:27:01 +0530

Robert,

Are you using Persistence.createEMF()? What exception are you seeing?
Here is what one has to do:

/The Java SE bootstrapping API (Persistence.createEntityManagerFactory)
relies on Thread's context class loader to be set properly for two reasons:
          to discover persistence units and JPA domain classes,
      .
          to discover Persistence Provider.
      .
While it is easy to work around the first one by just setting the
context class loader to the bundle
class loader before making the call to the
Persistence.createEntityManagerFactory,
the latter is hard to fix, as the bundle does not typically have a
direct dependency on Persistence
Provider. Fortunately, GlassFish Server can influence the resolution of
persistence providers using
a custom implementation of JPA SPI called
javax.persistence.spi.PersistenceProviderResolver.
This custom resolver can be enabled by setting the following property to
true in
$GLASSFISH_HOME/glassfish/osgi/felix/conf/config.properties:

org.glassfish.osgijpa.extension.useHybridPersistenceProviderResolver=true

It is by default set to false in that file.
/
So, you have to set the context class loader temporarily. You can look
at our sample [1].

Thanks,
Sahoo

[1]
http://java.net/projects/glassfish/sources/svn/content/trunk/fighterfish/sample/sample.uas/sample.uas.entities/src/main/java/org/glassfish/fighterfish/sample/uas/entities/EntitiesActivator.java?rev=47359

nb: Next time, please include exception stack trace.

On Wednesday 08 June 2011 05:48 AM, Robert Weeks wrote:
> Hello -
>
> Is there any special tricks to getting the persistence.xml file to be read correctly from within a bundle? We seem to not be able to get it to recognize at all - no matter where we put it (inside/outside META-INF), setting Bundle-ClassPath, etc.
>
> Thanks for any information.
>
>
> Robert Weeks
> Lead Developer - Framework and UI
> EXTENSION, INC.
> Email: rweeks_at_ext-inc.com
> Office: 260-797-0200 x4228
> General: 877-207-3753
> www.OpenTheRedBox.com
>
> Download the FREE EXTENSION Mobile App for iPhone and iPod Touch
> http://www.opentheredbox.com/iPhone_appDemo.php
>