users@glassfish.java.net

Re: Two EJB modules inside one EAR and entity manager

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 10 Oct 2007 14:10:13 -0700

Hi Witold,

You do need to put your entities into a separate jar into ear's lib/ directory.

By having them inside a module, you limit their scope/visibility to that module
only. A global PU means that it's shared, not duplicated, and if you inject an
EM in your EJBs, the beans participating in the same transaction will share the
same persistence context.

Regards,
-marina

Witold Szczerba wrote:
> Hi there,
> in my company, we are developing an enterprise application (EAR).
> Right now, almost all the functionality is inside one EJB module which
> we call Core Module.
>
> During development, I noticed that in the core module, there are few
> services very specific to the current customer's business logic and
> this particular business conditions can change from time to time. So,
> for me it looks like the core module is too much internally coupled,
> so I would like to split my EJB module, so the Core would be decoupled
> from those very specific conditions.
>
> So I created another module, lets call it CompanyX EJB Module which
> will be like a plug-in for the Core, it is dependent on the Core
> module's API, extending it functionality. In the future we can create
> CompanyY EJB Module or make changes in the CompanyX module without
> touching the Core.
>
> I have no problem accessing Core's services from within CompanyX
> services, simple
> @EJB SomeCoreServiceLocal
> works great, but I _cannot_ access Core's entity manager.
>
> I have tried something like this:
> @PersistenceContext(unitName="corePU")
> private EntityManager em;
>
> But it does not work, I have no idea how to inject the entity manager
> of Core EJB into CompanyX EJB service.
>
> Once I've heard suggestions that I should tear out all my entities +
> persistance.xml from Core service and put it inside some jar at the
> EAR level but I do not want to decouple core entities from core EJB
> module. Moreover if I do that, I would encounter lot of troubles (like
> transaction propagation) because CompanyX EJB would create its own EM
> context for accessing entities while it is supposed to work like a
> plug-in, not as a separate EJB.
>
> So, in short: is it actually possible to access entity manager of one
> EJB module from within another EJB module inside the same EAR?
>
> Thanks,
> Witold Szczerba
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>