users@glassfish.java.net

Re: Library jar with JPA entity classes

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Wed, 06 Apr 2011 09:33:08 +0530

This is very much possible using OSGi in GlassFish. You can package your
entities and persistence.xml in a separate OSGi bundle which will export
the EMF as a service. You can then use the EMF from other EJB/OSGi
bundles as a service. Full sample at:

http://java.net/projects/glassfish/sources/svn/show/trunk/fighterfish/sample/sample.uas/sample.uas.entities
http://java.net/projects/glassfish/sources/svn/show/trunk/fighterfish/sample/sample.uas/sample.uas.ejbservice2

Sahoo

On Sunday 03 April 2011 07:05 PM, forums_at_java.net wrote:
> Hi,
>
> I have read in the FAQ's that one cannot share a PU across multiple
> applications deployed in the EJB container. My practical experience has
> indeed shown that this is error prone as the first application works
> fine,
> but subsequent deployed EARs get errors due to the entity classes
> being in
> different classloaders and throwing "com.xxx.yy cannot be cast to
> com.xx.yy"
> etc.
>
> In this light, there must be a way of achieving my use case. Here is
> what I
> want to achieve:
>
> - I want to create a library jar that can be used by many EJB modules,
> which
> in turn are deployed in different EAR's (the library jar would be
> packagedin
> the /lib directory of each EAR). I dont want a single ear containing all
> theEJB's, as it would be huge and wouln't allow me to redeploy a single
> component at a time. The separate ears are to be deployed to a single
> Glassfish instance.
>
> - The jar needs a persistence unit that allows it to connect to a mysql
> database
>
> - The jar has JPA entity classes for persistence
>
>
>
> Is there a way I can achieve this? If I try to accomplish this now,
> the EMF
> can be created easily enough, but it seems that its shared in a container
> level classloader for all the EAR's and this causes issues when using the
> entity classes (the casting issue mentioned).
>
>
>
> Paul
>
>
> --
>
> [Message sent by forum member 'paulcb']
>
> View Post: http://forums.java.net/node/788153
>
>