users@glassfish.java.net

Re: Sharing EntityManagerFactory between spring app and EJB3.1 a

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Fri, 27 Jan 2012 07:10:21 +0530

I thought you would have bundled hibernate along with your app. Thanks
for confirming.

I am pretty sure there is a way to configure Spring to give you a
reference to an OSGi service, so you could explore that if you don't
want to take the simpler approach of using @OSGiService.

You don't have to do emf.createEM in every DAO. You could use something
like a CDI producer or EJB interceptor to do it for you. I use
interceptor in my test case at
https://svn.java.net/svn/glassfish~svn/trunk/fighterfish/test/testapp/test.app16.mdb/src/main/java/org/glassfish/fighterfish/test/app16/mdb/TestApp16MDB_BMT.java

If you don't share EMF, then you don't share the second level cache
which means a penalty on performance. Moreover, many times JPA providers
assume that a single application (a single second level cache) owns the
database, which means if you have multiple second level caches, they may
actually be out of synch with each other.

Sahoo
On Friday 27 January 2012 12:15 AM, forums_at_java.net wrote:
> Hi Sahoo,
>
> Is there a solution that only entails a configuration change in spring
> (Same
> as described here [1], getting EMF by jndi)? It looks simpler. Also,
> with
> the osgi solution it requires replacing @PersistenceContext annotation
> with
> calling emf.getEntityManager() in all the DAOs in the spring app.
>
> Regading hibernate, we've managed to work with hibernate probably
> because we
> don't have "pure" osgi bundles. Our bundles contain hibernate in their
> WEB-INF/lib and not consuming hibernate from hibernate osgi bundle. Do
> you
> think I should be able to register and consume EMF in such bundles?
> Anyway, what do I lose if I'm not sharing EMF (except from duplicate
> configuration of provider and other props)? maybe it's not that bad to
> share
> only DS..
> Thanks!
>
>
>
> [1]
> http://forum.springsource.org/showthread.php?102028-Spring-JPA-Glassfish-JNDI
>
> --
>
> [Message sent by forum member 'Karo']
>
> View Post: http://forums.java.net/node/882978
>
>