2.5. Declaring EJB references

More information about EJB references in JOnAS, including local references from EJB 2.0, may be found in the JOnAS documentation.

2.5.1. References between beans in the same jar

This section explains how to declare references between beans that are packaged in the same jar. As only the standard deployment descriptor ejb-jar.xml is concerned, 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. and you must also declare an ejb-link attribute in the ejb-ref element of the bean. There is nothing to add in the JBoss or JOnAS specific descriptors. In the following example the session bean SB_BrowseRegions calls methods on the Region entity bean. So for SB_BrowseRegions you need an ejb-ref element in the ejb-jar.xml file that references the bean Region:

Common ejb-jar.xml file for SB_BrowseRegions:

<ejb-jar>
    <enterprise-beans>
       <session>
    	    <description>Deployment descriptor for SB_BrowseRegions Bean</description>
            <ejb-ref>
               <description>This is the reference to the region bean</description>
               <ejb-ref-name>ejb/Region</ejb-ref-name>
               <ejb-ref-type>Entity</ejb-ref-type>
               <ejb-link>Region</ejb-link>
               <home>edu.rice.rubis.beans.RegionHome</home>
               <remote>edu.rice.rubis.beans.Region</remote>
            </ejb-ref>
      <session>
    <enterprise-beans>
<ejb-jar>
         

2.5.2. References between beans in different jars but in the same ear

This section explains how to declare references between beans that are packaged in different jars, but that are packaged in the same J2EE application (ear). With JBoss 2.4 and JOnAS versions before 2.6, you should proceed as if the beans were in separate jars and in separate ears, see next section. With JOnAS (from version 2.6), you proceed in the standard way, i.e. only the standard deployment descriptor is concerned. So for migrating from JBoss to JOnAS, just suppress the corresponding part of the jboss.xml file and add the ejb-link element to the ejb-jar.xml.

With JOnAS you have to declare an ejb-ref element in the ejb-jar.xml. and you must also declare an ejb-link attribute in the ejb-ref element of the bean. There is nothing to add in the JOnAS specific descriptors. The value of the ejb-link element should be the name of the target bean, prefixed by the name of the containing ejb-jar file and '#' (e.g. "My_EJBs.jar#bean1"). In the following example the session bean SB_BrowseRegions calls methods on the Region entity bean. So for SB_BrowseRegions you need an ejb-ref element in the ejb-jar.xml file that references the bean Region. If the Region bean is in a separate Region.jar jar file, the reference will be as below:

ejb-jar.xml file for SB_BrowseRegions:

<ejb-jar>
    <enterprise-beans>
       <session>
    	    <description>Deployment descriptor for SB_BrowseRegions Bean</description>
            <ejb-ref>
               <description>This is the reference to the region bean</description>
               <ejb-ref-name>ejb/Region</ejb-ref-name>
               <ejb-ref-type>Entity</ejb-ref-type>
               <ejb-link>Region.jar#Region</ejb-link>
               <home>edu.rice.rubis.beans.RegionHome</home>
               <remote>edu.rice.rubis.beans.Region</remote>
            </ejb-ref>
      <session>
    <enterprise-beans>
<ejb-jar>
         

2.5.3. References between beans in different jars and different ears

This section explains how to declare references between beans that are packaged in different jars and in different ears.

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.

In the following example the session bean SB_BrowseRegions calls methods on the Region entity bean but the beans are packaged in different jars. So for SB_BrowseRegions you need an ejb-ref element in the ejb-jar.xml file and a jonas-ejb-ref element in the jonas-ejb-jar.xml file that references the bean Region instead of an ejb-ref elment in the the jboss.xml:

Common ejb-jar.xml file for SB_BrowseRegions:

<ejb-jar>
    <enterprise-beans>
       <session>
    	    <description>Deployment descriptor for SB_BrowseRegions Bean</description>
            <ejb-ref>
               <description>This is the reference to the region bean</description>
               <ejb-ref-name>ejb/Region</ejb-ref-name>
               <ejb-ref-type>Entity</ejb-ref-type>
               <home>edu.rice.rubis.beans.RegionHome</home>
               <remote>edu.rice.rubis.beans.Region</remote>
            </ejb-ref>
      <session>
    <enterprise-beans>
<ejb-jar>
         

Example of jboss.xml file for SB_BrowseRegions:

<jboss>
    <session>
        <ejb-name>SB_BrowseRegions</ejb-name>
        <ejb-ref>
            <ejb-ref-name>ejb/Region</ejb-ref-name>
            <jndi-name>protocol://serverName/directory/RegionHome</jndi-name>
        </ejb-ref>
    </session>
</jboss>
         

Here is the equivalent jonas-ejb-jar.xml file for SB_BrowseRegions:

<jonas-ejb-jar>
    <jonas-session>
        <ejb-name>SB_BrowseRegions</ejb-name>
        <jonas-ejb-ref>
            <ejb-ref-name>ejb/Region</ejb-ref-name>
            <jndi-name>RegionHome</jndi-name>
        </jonas-ejb-ref>
    </jonas-session>
</jonas-ejb-jar>