users@glassfish.java.net

Re: OSGi Persistence Bundles

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Tue, 14 Jun 2011 05:52:20 +0530

My initial target was to make sure we allow use JPA features like lazy
loading, etc to work in OSGi in an enterprise set up where DataSource
and JTA are primarily used. So, I focused on that. GlassFish allows the
following:

a) Use JPA from their EJB Bundles or WABS as you have already figured
out from the doc. This follows the standard enterprise pattern where
developers use a facade to their data layer. In this case, typically
users gets hold of an EMF or EM using regualr JPA annotations like
@PersistenceUnit/Context.

b) Package their JPA entities in a standalone entities.jar. This is
pretty close to enterprise OSGi JPA spec except that GlassFish does not
automatically export the EMF or EMFBuilder. Users can write two lines of
code in their activator to do this as demonstrated in our sample at [1].
In fact, it won't be that difficult to have an extender to do this
automatically, it's just that I have not seen the need for it yet. BTW,
in this case also, user can configure their persistence unit to use JTA
and DataSources.

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=47457

On Tuesday 14 June 2011 02:21 AM, Harald Wellmann wrote:
> Does Glassfish 3.1 support OSGi Persistence Bundles according to the
> OSGi Enterprise JPA Service Spec?
>
> After deploying a JAR with a persistence unit and the required OSGi
> headers to Glassfish as OSGi bundle, I was expecting to see an
> EntityManagerFactory for this persistence unit in the service
> registry, but I didn't.
>
> After reading
>
> http://wikis.sun.com/download/attachments/209655166/GF-OSGi-Features-1.0.pdf
>
>
> and looking at the code samples, it seems only EJB JARs and WARs can
> be hybrid bundles, but persistence units/bundles are not...?
>
> In one of the EJB code samples, the classes from a persistence unit
> were copied into the bundle, which is not really what you want.
>
> When a persistence bundle gets deployed, the container should register
> the EMF in the OSGi service registry, and hybrid EJB bundles should be
> able to inject a @PersistenceContext via the OSGi service registry.
>
> Is this possible at all, or on the roadmap at least?
>
> BTW: Sahoo, thanks a lot for writing this OSGi Features document - the
> official GlassFish docs don't give much space to OSGi, so your
> overview is extremely helpful.
>
> Regards,
>
> Harald
>