The <ejb-ref> tag is used by the Bean Provider to indicate a psuedo name to the assembler, that he is referring to a EJB in his code. And then it is the responsibilty if the App Assembler to map that psuedo name to the actual EJB's jndi name on the container.
Also by using the <ejb-ref> tag, the developer can directly use the following code..
Context c = new InitialContext();
Here in the InitialContext() the developer need not pass any parameter to specify the jdni factory and server name.
This way the code becomes deployable to any container as no specific env. values are passed in the InitialContext().
Now the question is --
Consider the scenario, i have a Address EJB deployed on a container on machine A. And there is another EJB Customer referring to Address, this Customer EJB is deployed in a container on machine B.
In the code of Customer the developer has used -- Context c = new InitialContext(); for accessing the Address EJB.
And he has specified an <ejb-ref> element for the Customer EJB.
Bean devloper is not passing any info to InitialContext(), and also in the ejb-jar.xml file, for the <ejb-ref> of Customer we do not have any tag which says on which machine the Address EJB is deployed.
Also during deployment the deployer only gives maps the psuedo name of <ejb-ref> to the JNDI name of the referenced EJB. He also not specifies the machine name and address.
So how this <ejb-ref> works, when we have to ejb's deployed on two diffrent machines and One want to use the other?
I hope all the above explanation makes sense, even if not, please help me in knowing the <ejb-ref> element better.
This just won't work for the following reason (EJB 2.0 spec, section 20.3):
The deployment descriptor also allows the Application Assembler to link an EJB reference declared in one enterprise bean to another enterprise bean contained in the same ejb-jar file, or in another ejb-jar file in the same J2EE application unit. The link is an instruction to the tools used by the Deployer that the EJB reference should be bound to the home of the specified target enterprise bean.
Given that your beans Address and Customer are on two different machines, it means that they are part of two different J2EE applications deployed on each machine and thus the rule mentioned above is not satisfied.
...even if not, please help me in knowing the <ejb-ref> element better.
(1) BeanProvider sanjivcts is implementing the Customer EJB. He is using the Address EJB that is provided by BeanProvider Severin, and he's referring to this bean under the name <ejb-ref-name>ejb/Address<ejb-ref-name>.
(2) BeanProvider Severin is implementing the Address EJB, he's publishing the Bean under the name <ejb-name>CustomerAddresses<ejb-name>
they don't know each other
(3) AppAssembler Valentin links Severin's implementation to sanjivcts, using the <ejb-link>CustomerAddresses<ejb-link> tag in the <ejb-ref>
Joined: Aug 26, 2001
Actually, it is possible for one bean to access another on a different machine and here is how