users@glassfish.java.net

Re: Sharing EntityManagerFactory between spring app and EJB3.1 app deployed on glassfish

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Wed, 25 Jan 2012 06:58:34 +0530

If you use Eclipselink as a provider, then it's definitely possible to
export EMF as a service from one bundle and use it from other bundles.
See section #8 of [1]. You can also find examples of the same at [2] &
[3]. [2] exports EMF as a service and [3] consumes the service. I don't
know how you have got Hibernate working from your OSGi bundles, but if
you can create an EMF and export it as a service, then you can consume
it other bundles as a service.

Sahoo

[1] http://glassfish.java.net/public/GF-OSGi-Features.pdf
[2]
http://java.net/projects/glassfish/sources/svn/show/trunk/fighterfish/sample/entities
[3]
http://java.net/projects/glassfish/sources/svn/show/trunk/fighterfish/sample/ejbservice2

On Wednesday 25 January 2012 05:02 AM, forums_at_java.net wrote:
> Hi,
> I have the following requirement:
> 2 web apps, one is Spring, the other is EJB3.1.
> Also, both are osgi bundles.
> Both apps should access the same datasource.
> In the spring app, I already tried to inject the datasource from jndi
> (defined in GF). works fine.
> The question is, can/should I also share the EntityManagerFactory?
> That is,
> define it in the ejb bundle and use the same EMF in the spring bundle
> (such
> that the provider, hibernate, and its properties wil be defined only
> once)?
> does it make sense?
> If so, how can I use it in the spring app?
> Thanks.
>
>
>
> --
>
> [Message sent by forum member 'Karo']
>
> View Post: http://forums.java.net/node/882978
>
>