<ejb-ref-name> is bound to environment property
java:comp/env. And as you know, each EJB has its own private namespace java:comp/env. So you can have duplicate ejb-ref-name in an ejb-jar.xml file. But <ejb-ref-name> has to be unique within the given enterprise bean declaration.
The following example would help:
An application has 4 EJBs: EJB1, EJB2, EJB3 and EJB4.
Lets say EJB1 references to EJB2 & EJB4. EJB3 references only to EJB4.
Then you can have a deployment descriptor like as follows:
//entity description for EJB1
<entity>
<ejb-name>EJB1</ejb-name>
....
<ejb-ref>
<ejb-ref-name>ejb/myEJB1</ejb-ref-name> .....
<env-link>EJB2</env-link> [This is the ejb-name of EJB2]
</ejb-ref>
<ejb-ref>
<ejb-ref-name>ejb/myEJB2</ejb-ref-name> [This name cannot be myEJB1]
.....
<env-link>EJB2</env-link> [This is the ejb-name of EJB2]
</ejb-ref>
...
</entity>
//entity description for EJB3
<entity>
<ejb-name>EJB3</ejb-name>
....
<ejb-ref>
<ejb-ref-name>ejb/myEJB1</ejb-ref-name> .....
<env-link>EJB4</env-link> [This is the ejb-name of EJB4]
</ejb-ref>
...
</entity>
...
As you can see from the above both EJB1 and EJB3 use the same <ejb-ref-name> "ejb/myEJB1" to refer to different EJBs (EJB2 and EJB4 respectively).
The key points to remember:
1) Each enterprise bean defined in an ejb-jar.xml gets its own private namespace: java:comp/env
2) <ejb-link> is used by application assembler to link the logical name (ejb-ref-name) to the actual referenced ejb.
Hope this helps.