users@glassfish.java.net

Re: Style question about returning JPA entities from EJB

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Sat, 10 Nov 2007 19:15:04 -0500

This reminds me of an other related question. My web project uses EJB
local session beans. Since they are not remote there are no stubs, and
therefore my web project has a build dependency on the EJB project. I
can't think of an other way to use a local EJB without having a build
dependency on the EJB project. Is that correct? If that's the case,
then JPA entities could live in the EJB project instead of a separate
shared JAR.


Thanks,
Ryan

Ryan de Laplante wrote:
> That makes sense, I forgot that JPA can be used in Java SE. I thought
> that the persistence.xml must be in an EJB jar or WAR file.
>
> Thanks,
> Ryan
>
> Marina Vatkina wrote:
>> Normally it will leave with the entities, which will also allow you
>> to test your PU outside the container. But if you have some reasons
>> to exclude it, it can be placed with the component (with the
>> <jar-file> element (see the spec) "specified relative to the root of
>> the persistence unit (e.g., utils/myUtils.jar).".
>>
>> Regards,
>> -marina
>>
>> Ryan de Laplante wrote:
>>> Thank you. The persistence.xml would still live inside of the EJB
>>> project, right?
>>>
>>> Thanks,
>>> Ryan
>>>
>>> Marina Vatkina wrote:
>>>
>>>> I think your best option would be to use a separate jar for the
>>>> entities that is placed under <ear>/lib directory.
>>>>
>>>> Regards,
>>>> -marina
>>>>
>>>> Ryan de Laplante wrote:
>>>>
>>>>> I'm not sure where else to ask a question like this.
>>>>>
>>>>> Back in the EJB 2.x days with CMP, the CPM entities were not
>>>>> returned by session beans. The entity would be converted into
>>>>> POJO value objects before being returned. I used to put the value
>>>>> object POJOs in a common jar file that the EJB project and EJB
>>>>> client project would depend on.
>>>>> In the Java EE5 world, I have been returning the actual JPA
>>>>> entities from my EJB3 session beans. Since the JPA entity classes
>>>>> live inside of the EJB jar file, the persistence.xml lives in
>>>>> there too, and my web project has a build dependency on the EJB
>>>>> project. This hasn't been a big deal for me since I use EJB
>>>>> Local, but I've always wondered if this is the right way to do it.
>>>>>
>>>>> Can anyone share with me the Java EE5 patterns you use, or links
>>>>> to pages that talk about this?
>>>>>
>>>>>
>>>>> Thanks,
>>>>> Ryan