Sun Java System Application Server Platform Edition 9 Upgrade and Migration Guide

Migrating EJB Client Applications

Existing EJB 2.1 and earlier applications are supported to run unchanged in EJB 3.0 containers. All EJB 3.0 implementations support EJB 1.1, EJB 2.0, and EJB 2.1 deployment descriptors for applications written to earlier versions.

Clients written to the new EJB 3.0 API

A client written to the EJB 3.0 API may be a client of a component written to the EJB 2.1 or earlier API. Such clients may access components written to the EJB 3.0 APIs and components written to the earlier EJB APIs within the same transaction. Such clients access components written to the earlier EJB APIs using the EJB 2.1 client view home and component interfaces. The EJB annotation may be used for the injection of home interfaces into components that are clients of beans written to the earlier EJB client view.

Declaring EJBs in the JNDI Context

In Application Server 9, EJBs are systematically mapped to the JNDI sub-context ejb/. If you attribute the JNDI name Account to an EJB, the Application Server 9 automatically creates the reference ejb/Account in the global JNDI context. The clients of this EJB therefore have to look up ejb/Account to retrieve the corresponding home interface.

Let us examine the code for a servlet method deployed in Sun ONE Application Server 6.x.

The servlet presented here calls on a stateful session bean, BankTeller, mapped to the root of the JNDI context. The method whose code you are considering is responsible for retrieving the home interface of the EJB, to enable a BankTeller object to be instantiated, and a remote interface for this object to be retrieved, so that you can make business method calls to this component.

   * Look up the BankTellerHome interface using JNDI.
private BankTellerHome lookupBankTellerHome(Context ctx)
      throws NamingException
      Object home = (BankTellerHome) ctx.lookup("ejb/BankTeller");
      return (BankTellerHome) PortableRemoteObject.narrow(home, 
    catch (NamingException ne)
      log("lookupBankTellerHome: unable to lookup BankTellerHome" +
          "with JNDI name ’BankTeller’: " + ne.getMessage() );
      throw ne;

As the code already uses ejb/BankTeller as an argument for the lookup, there is no need for modifying the code to be deployed on Application Server 9.

Using EJB JNDI References

This section summarizes the considerations when using EJB JNDI references. Where noted, the consideration details are specific to a particular source application server platform.

Placing EJB References in the JNDI Context

It is only necessary to modify the name of the EJB references in the JNDI context mentioned above (moving these references from the JNDI context root to the sub-context ejb/) when the EJBs are mapped to the root of the JNDI context in the existing WebLogic application.

If these EJBs are already mapped to the JNDI sub-context ejb/ in the existing application, no modification is required.

However, when configuring the JNDI names of EJBs in the deployment descriptor within the Sun Java Studio IDE, it is important to avoid including the prefix ejb/ in the JNDI name of an EJB. Remember that these EJB references are automatically placed in the JNDI ejb/ sub-context with Application Server 9. So, if an EJB is given to the JNDI name BankTeller in its deployment descriptor, the reference to this EJB will be translated by Application Server 9 into ejb/BankTeller, and this is the JNDI name that client components of this EJB must use when carrying out a lookup.

Global JNDI context versus local JNDI context

Using the global JNDI context to obtain EJB references is a perfectly valid, feasible approach with Application Server 9. Nonetheless, it is preferable to stay as close as possible to the Java EE specification, and retrieve EJB references through the local JNDI context of EJB client applications. When using the local JNDI context, you must first declare EJB resource references in the deployment descriptor of the client part (web.xml for a Web application, ejb-jar.xml for an EJB component).