More information about the ejb-ref element of ejb-jar.xml

Discussions

EJB programming & troubleshooting: More information about the ejb-ref element of ejb-jar.xml

  1. Hello,

    I am currently studying ejbs and I came across the ejb-ref element of the ejb-jar.xml file. I am in reference to O'Reilly Entreprise JavaBeans book. The book says that, thanks to the ejb-ref element it is possible to access one ejb from another ejb with the following client code:

    [code]
    InitialContext jndiContext = new InitialContext();
    Object ref = jndiContext.lookup("java:comp/env/ejb/ProcessPaymentHomeRemote");
    ProcessPaymentHomeRemote home = (ProcessPaymentHomeRemote) PortableRemoteObject.narrow(ref, ProcessPaymentHomeRemote.class);
    [/code]

    I thought one could invoke the above client code without the ejb-ref element being present in the ejb-jar.xml... I am right or wrong?

    Then why the need for the ejb-ref element? Can anyone give me a concrete example of usage of the ejb-ref element where the ejb-ref element really is useful? What are the advantages of using the ejb-ref element?

    Thanks in advance,

    Julien Martin.
  2. You can access EJB without ejb-ref, in that case you have to hardcode the other bean's JNDI name in your bean's code.

    This might help you: http://www.theserverside.com/discussions/thread.tss?thread_id=25668

    Senthil
  3. ejb-ref[ Go to top ]

    Thanks a lot for your reply Senthil,

    If I understand you, ejb-ref avoids us to have to re-specify the following information for inter ejb calls:

    ******************************
    Context.INITIAL_CONTEXT_FACTORY
    Context.PROVIDER_URL
    Context.SECURITY_PRINCIPAL
    Context.SECURITY_CREDENTIALS
    ******************************

    but instead of having one information hardcoded we have another hardcoded (e.g. java:comp/env/ejb/AddressHomeLocal).

    Am I right?

    Julien.