Hi Erik,
That's right, you can't use @PersistenceContext inside a WAB to get hold
of an EM that's produced by an EMF belonging to a standalone JPA bundle.
I don't think it's enough to bring in Enterprise JPA from Apache Aries
to make it happen. You need the support in the web container to be able
to resolve the @PersistenceContext properly.
My suggestion would be to use application managed entity manager. You
can use a little bit of CDI to manage transactions and write a bean to
act as produce of EntityManager. Take a look at this test source [1]
code for example. If you don't want to use CDI, then you can follow the
sample code [2].
HTH,
Sahoo
nb: I don't really follow this mailing group actively. Feel free to copy
me directly if you need more information.
[1]
https://java.net/projects/glassfish/sources/svn/content/trunk/fighterfish/test/app/app16.mdb/src/main/java/org/glassfish/fighterfish/test/app16/mdb/TestApp16MDB_BMT.java
[2]
https://java.net/projects/glassfish/sources/svn/content/trunk/fighterfish/sample/uas/advservice/src/main/java/org/glassfish/fighterfish/sample/uas/advservice/AdvUserAuthServiceImpl.java?rev=64304
On 21/09/16 8:10 am, Erik Brakkee wrote:
> Hi,
>
>
> I am porting an application to Glassfish that uses JPA. In particular,
> there is one bundle containing a JPA persistence unit (and all
> entities) and there is a WAR module that depends on the JPA module.
>
> Now, reading in the "OSGI Application Development using Glassfish
> Server" it seems that the only supported method is through
> application-managed entity managers. In particular, I have tried
> injecting the EntityManager in a servlet class of the WAR using
> @PersistenceContext but this fails.
>
> One option that could work is to use Enterprise JPA from Apache Aries.
> Another option would be use an application managed entity manager and
> manage integration with transaction management myself.
>
> What would be the recommended way to do this integration? In any case,
> dynamic deployment of different bundles is not an issue. The
> application server will always be started with all our bundles installed.
>
> Cheers
> Erik