Declaring EJB References

This section explains how to declare references between beans. More information about EJB references in JOnAS, including local references from EJB 2.0, may be found in the JOnAS Documentation.

For the standard deployment descriptor ejb-jar.xml, there is no difference between JOnAS and JBoss. With both JBoss and JOnAS you have to declare an ejb-ref element in the ejb-jar.xml file. When the two beans are in the same EAR this <ejb-ref> declaration must contain an <ejb-link> element. The value of the <ejb-link> element should be the name of the bean being referenced. If the bean being referenced is in a different JAR then the bean name should be prefixed with its JAR name followed by a "#" character. This is required to uniquely identify beans within an EAR since distinct ejb jar files may contain identically named beans.

Table 2-2. Value for the ejb-link Element

ValueDescription
<ejb-link>BeanName</ejb-link>
Use this form when creating a reference between beans in the same ejb-jar.
<ejb-link>JarName.jar#BeanName</ejb-link>
Use this form when creating a reference between beans in different ejb-jars, but in the same EAR.
noneOmit the <ejb-link> element when creating a reference between beans in different ears. In this case you will be required to add some vendor specific configuration in order to complete the link.

As described above, the only situation requiring vendor specific configuration is when creating a reference between beans in different ears. If your application makes use of such references you will need to migrate the vendor specific configuration for these references from META-INF/jboss.xml to META-INF/jonas-ejb-jar.xml.

With both JBoss and JOnAS you have to declare an <ejb-ref> element in the ejb-jar.xml but unlike when beans are in the same jar, you don't have to declare an <ejb-link> attribute. With JBoss you have to declare an <ejb-ref> element in jboss.xml and provide the full JNDI name of the bean. With JOnAS you have to declare a <jonas-ejb-ref> element in jonas-ejb-jar.xml that contains the JNDI name of the referenced bean home interface.

Example 2-6. Common ejb-jar.xml

<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>Bean Name</ejb-name>
      ...
      <ejb-ref>
        <description>Reference Description</description>
        <ejb-ref-name>ejb/RefName</ejb-ref-name>
        <ejb-ref-type>Entity|Session</ejb-ref-type>
        <home>HomeInterface</home>
        <remote>RemoteInterface</remote>
      </ejb-ref>
      ...
    <session>
  <enterprise-beans>
<ejb-jar>

Example 2-7. jboss.xml

<jboss>
  <enterprise-beans>
    <session>
      <ejb-name>Bean Name</ejb-name>
      ...
      <ejb-ref>
        <ejb-ref-name>ejb/RefName</ejb-ref-name>
        <jndi-name>JNDI Name</jndi-name>
      </ejb-ref>
      ...
    </session>
  </enterprise-beans>
</jboss>

Example 2-8. jonas-ejb-jar.xml

<jonas-ejb-jar>
  <jonas-session>
    <ejb-name>Bean Name</ejb-name>
    ...
    <jonas-ejb-ref>
      <ejb-ref-name>ejb/RefName</ejb-ref-name>
      <jndi-name>JNDI Name</jndi-name>
    </jonas-ejb-ref>
    ...
  </jonas-session>
</jonas-ejb-jar>