users@glassfish.java.net

Re: Two EJB modules inside one EAR and entity manager

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Sun, 24 Jan 2010 23:56:00 +0100

2007/10/11 Sahoo <Sahoo_at_sun.com>:
> See if [1] helps in clarifying PC Propagation issues.
>
> Thanks,
> Sahoo
>
> [1]
> http://weblogs.java.net/blog/ss141213/archive/2006/10/persistence_con.html
>
> Marina Vatkina wrote:
>>
>> Witold Szczerba wrote:
>>>
>>> 2007/10/10, Marina Vatkina <Marina.Vatkina_at_sun.com>:
>>>
>>>> Hi Witold,
>>>>
>>>> You do need to put your entities into a separate jar into ear's lib/
>>>> directory.
>>>
>>>
>>> That is what I really wanted to avoid, because using separate jar for
>>> entities is not so comfortable :/
>>> If I would do that - where am I suppose to place persistence.xml file?
>>
>> Into entities.jar
>>
>>> Inside that jar, so it would be available for all EJB modules or each
>>> module has to declare its own persistence.xml and specify every entity
>>> class - one by one inside its own PU?
>>
>> No, by that they'll share the same PU.
>>
>>>
>>>
>>>> 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.
>>>
>>>
>>> This is really strange to me. Session beans are inside EJB module and
>>> you can call them from everywhere... I can't see why this is not the
>>> case with entity manager.
>>
>> It's the scoping rules of PUs. Did you read 6.2.2 Persistence Unit Scope
>> of the JPA spec?
>>
>> HTH,
>> -marina
>>
>>>
>>>
>>>> -marina
>>>
>>> Thanks,
>>> Witold Szczerba
>>>


Thanks for help!
Regards,
Witold Szczerba