JBoss.org Community Documentation

Chapter 9. Introduction to using EJB2.1 client adaptors with EJB3

EJB 3.0 is backward compatible to EJB 2.x clients and supports the use of local and remote home interfaces as well as initialization methods (e.g. ejbCreate()). This capability is configured through annotations and/or through deployment descriptors.

Take a look at org.jboss.tutorial.ejb21_client_adaptors.bean.Session1Bean. Note that the class is annotated with @RemoteHome and the ejbCreate() method is annotated with @Init. The former annotation indicates that the bean provides a EJB 2.1 style home interface. The latter annotation indicates that when the create() method is invoked from the home interface, the bean is initialized via the ejbCreate method.


The initialization method (annotated with @Init) name is not restricted to be ejbCreate(). You can specify any other name for that method.

org.jboss.tutorial.ejb21_client_adaptors.bean.Session2Bean illustrates the use of a local home interface.


There's a very important difference between the remote and a business-remote interface. The EJB2.x remote interfaces, which extend from EJBObject, are referred through the <remote> tag in the ejb-jar.xml. On the other hand, the EJB3 style Plain Old Java Interface which is implemented by your EJB3 style POJO bean is known as the business-remote interface and is represented by the @Remote and it's corresponding <business-remote> tag in ejb-jar.xml. Similar is the case with <local> and the <business-local> tags in ejb-jar.xml.

In this tutorial, you will notice that we are using remote and local interfaces and not business-remote and business-local interfaces.


Since we are not using any business-remote or business-local interfaces, in this tutorial, unlike the "jndibinding" tutorial, we cannot use the @RemoteBinding or @LocalBinding annotations to bind the EJBs. Instead, we configure the jndi-names for these beans through the META-INF/jboss.xml:



Similarly, org.jboss.tutorial.ejb21_client_adaptors.bean.DeploymentDescriptorSession1Bean and org.jboss.tutorial.ejb21_client_adaptors.DeploymentDescriptorSession2Bean mimic the behavior of the first two beans, but use deployment descriptors to indicate the home interface(s) and initialization method(s). Take a look at the META-INF/ejb-jar.xml. Note the home and local-home tags that indicate the respective home interfaces. Also, note the init-method tag that indicates the initialization method(s) executed when beans are created via the home interface(s).

Building and Running

From the command prompt, move to the "ejb21_client_adaptors" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”

Ant Users:

Make sure your JBossAS-5.x is running

$ ant
$ ant run

     [java] Session1 init value is initialized
     [java] Session2 init value is initialized
     [java] DeploymentDescriptor Session1 init value is initialized
     [java] DeploymentDescriptor Session2 init value is initialized


Maven Users: Make sure the AS is not running.

$ mvn clean install -PRunSingleTutorial