Calling EJB from another EJB

Discussions

EJB design: Calling EJB from another EJB

  1. Calling EJB from another EJB (4 messages)

    Hi All,

    I am trying to call and Entity EJB from inside a Session EJB. What is the procedure I should follow. I am currently doing the normal JNDI lookup, POA narrow and invoke but it is not working. Is this the correct way of doing this.

    Cheers,

    James.

    Threaded Messages (4)

  2. Calling EJB from another EJB[ Go to top ]

    If u are doin the JNDI lok up thats enough
    No need to narrow down the Object...
    HTH
    Sahil

    p.s:Chk whether the Bean is registered with the name that u are givin at the time of performing the lookup
  3. Calling EJB from another EJB[ Go to top ]

    Hi james

    Did you add <ejb-ref> tag ( and its child tags) in your ejb-jar.xml of session bean.

    Unless you mention EJBReference of Entity Bean (in descriptor of session bean) being called from Session Bean, you cannot expect the session bean to call entity bean


    hope this will resolve your problem

    regards

    somal

  4. I don't think this is true... even if u don't have ejb ref , u can call entity beans from session beans .!!

    Krish
  5. According to the EJB 1.1 specs, section 14.3.1.1:

    "The Bean Provider [thats you!] must use EJB references to locate the home interfaces of other enterprise beans as follows."

    It then goes on to describe how to put an EJB reference in the deployment descriptor and give it a JNDI name that is usually of the form "ejb/XXXX". The code then uses the following to lookup the home interface:

    Object o = context.lookup("java:comp/env/ejb/XXXX");
    MyHome h = PortableRemoteObject.narrow(o, MyHome.class);

    This allows the bean deployer to bind the reference to a specific bean at deployment time; those bindings should not be hard-coded in the bean implementation class. Also note that the JNDI reference must be narrowed as usual.

    Many of the current EJB container implementations allow other ways to do it (e.g. without narrowing) but to do that is not complient and may fail on other vendor platforms or in future releases. If you want portable beans, you should follow the spec carefully.

    -Mark