ejb@glassfish.java.net

Re: Problem with injecting EJB 2 in EJB3

From: Kenneth Saks <Kenneth.Saks_at_Sun.COM>
Date: Mon, 06 Jul 2009 10:06:05 -0400

On Jul 6, 2009, at 9:48 AM, Dieter De Meyer wrote:

> Hello,
>
> At our project, we are trying to access an EJB 2 Session Bean from
> within an EJB3 Session Bean with the @EJB injection.
> Following the EJB FAQ on Java.Net, we configured our EJB3 as followed:
>
> @Stateless
> public class Foo implements fooService {
> @EJB(name = “ejb/local/BarBean”, beanInterface =
> BarLocal.class)
> private BarLocal bar;
> }
>
> The generated ejb-jar.xml contains the following code:
>
> <ejb-ref >
> <ejb-ref-name>ejb/local/ BarBean </ejb-ref-name>
> <ejb-ref-type>Session</ejb-ref-type>
> <remote>example.BarLocal</remote>
> </ejb- ref>
>
> Following the FAQ, I would expect the following:
>
> <ejb-local-ref>
> <ejb-ref-name>ejb/local/ BarBean </ejb-ref-name>
> <ejb-ref-type>Session</ejb-ref-type>
> <local>example.BarLocal </local>
> </ejb- local-ref>
>
> Can someone tell me what we are doing wrong ?

Hi Dieter,

If you're accessing an EJB that was written to the EJB 2.x API, the
beanInterface should be set
to the Home or LocalHome interface of the target EJB. In that case,
the corresponding Remote or Local
2.x interface is derived from the Home/LocalHome.

@EJB(name="ejb/local/BarBean", beanInterface=BarLocalHome.class)

That should result in something like this :

<ejb-local-ref>
     <ejb-ref-name>ejb/local/BarBean</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
     <local-home>example.BarLocalHome</local-home>
     <local>example.BarLocal</local>
    ...
</ejb-local-ref>


>
> Kind regards,
>
> Dieter De Meyer.