Migrate enterprise bean code from V1.1 to V2.1

 

Overview

EJB V2.1-compliant beans can be assembled only in an EJB 2.1-compliant module, although an EJB 2.1-compliant module can contain a mixture of V1.x and V2.1 beans.

The EJB V2.1 specification mandates that prior to the EJB container starting a findByMethod query, the state of all enterprise beans that are enlisted in the current transaction be synchronized with the persistent store. (This action is so the query is performed against current data.) If V1.1 beans are reassembled into an EJB 2.1-compliant module, the EJB container synchronizes the state of V1.1 beans as well as that of V2.1 beans. As a result, you might notice some change in application behavior even though the application code for the V1.1 beans has not been changed.

The following information generally applies to any enterprise bean that currently complies with V1.1 of the EJB specification. For more information about migrating code for beans produced with the Rational Application Developer tool, see the documentation for that product. For more information about migrating code in general, see "Resources for learning."

 

Procedure

  1. In beans with container-managed persistence (CMP) version 1.x, replace each CMP field with abstract get and set methods. In doing so, make each bean class abstract.

  2. In beans with CMP version 1.x, change all occurrences of this.field = value to setField(value).

  3. In each CMP bean, create abstract get and set methods for the primary key.

  4. In beans with CMP version 1.x, create an EJB Query Language statement for each finder method.

    Note: EJB Query Language has the following limitations in Application Developer V5:

    • EJB Query Language queries involving beans with keys made up of relationships to other beans appear as invalid and cause errors at deployment time.

    • The IBM EJB Query Language support extends the EJB 2.1 spec in various ways, including relaxing some restrictions, adding support for more DB2 functions, and so on. If portability across various vendor databases or EJB deployment tools is a concern, then care should be taken to write all EJB Query Language queries strictly according to instructions described in Chapter 11 of the EJB 2.1 specification.

  5. In finder methods for beans with CMP version 1.x, return java.util.Collection instead of java.util.Enumeration.

  6. Update handling of non-application exceptions.

    • To report non-application exceptions, throw javax.ejb.EJBException instead of java.rmi.RemoteException.

    • Modify rollback behavior as needed: In EJB versions 1.1 and 2.1, all non-application exceptions thrown by the bean instance result in the rollback of the transaction in which the instance is running; the instance is discarded. In EJB 1.0, the container does not roll back the transaction or discard the instance if it throws java.rmi.RemoteException.

  7. Update rollback behavior as the result of application exceptions.

    • In EJB versions 1.1 and 2.1, an application exception does not cause the EJB container to automatically roll back a transaction.

    • In EJB V1.1, the container performs the rollback only if the instance has called setRollbackOnly() on its EJBContext object.

    • In EJB V1.0, the container is required to roll back a transaction when an application exception is passed through a transaction boundary started by the container.

  8. Update any CMP setting of application-specific default values to be inside ejbCreate (not using global variables, since EJB 1.1 containers set all fields to generic default values before calling ejbCreate, which overwrites any previous application-specific defaults). This approach also works for EJB 1.0 CMPs.

    Note: In Application Developer V5, there is a J2EE Migration wizard to migrate the EJB beans within an EJB 2.1 project from 1.x into 2.1 (one cannot just migrate individually selected beans). The wizard performs migration steps #1 to #2 above. It also migrates EJB 1.1 (proprietary) relationships into EJB 2.1 (standard) relationships, and maintains EJB inheritance.


 

Related Tasks


Task overview: Using enterprise beans in applications

 

See Also


Enterprise beans: Resources for learning

 



 

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.
Rational is a trademark of the IBM Corporation in the United States, other countries, or both.