Migrating code from EJB 1.1 to EJB 2.x
For projects converted from EJB 1.1 to EJB 2.x, steps must be taken to migrate existing EJB 1.1 code to EJB 2.x.
Note: EJB 2.x beans are only supported in an EJB 2.x project (although a 2.x project also supports 1.1 beans).
- For any CMP 1.1 bean, replace each CMP field with abstract getXXX and setXXX methods. (Then the bean class needs to be abstract.)
- For any CMP, create an abstract getXXX and setXXX method for the primary key.
- For any CMP 1.1 finder method, create an EJBQL (EJB Query Language) method for each finder method.
Note: EJB Query Language has the following limitations in Rational Application Developer V6.0:
- EJB Query Language queries involving EJBs with keys made up of relationships to other EJBs will appear as invalid and cause errors at deployment time.
- The IBM EJB Query Language support extends the EJB 2.x specification 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 tool 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.x specification.
- For any CMP 1.1 finder, return java.util.Collection instead of java.util.Enumeration.
- For any CMP 1.1 bean, change all occurrences of this.field = value to setField(value) in ejbCreate() and elsewhere throughout the code.
- Update your exception handling (rollback behavior) for non-application exceptions:
- Throw javax.ejb.EJBException instead of java.rmi.RemoteException to report non-application exceptions.
- In EJB 2.x and 1.1, all non-application exceptions thrown by the instance result in the roll back of the transaction in which the instance executed, and in discarding the instance.
- Update your Exception handling (rollback behavior) for application exceptions:
- In EJB 2.x and 1.1, an application exception does not cause the container to automatically roll back a transaction.
- In EJB 1.1, the container performs the rollback only if the instance was invoked using the setRollbackOnly() method on its EJBContext object.
- 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 will overwrite any previous application specific defaults).
Parent topic
Migrating Enterprise JavaBeans projects (EJB 1.1 to EJB 2.1)
Previous topic: Converting projects from EJB 1.1 to EJB 2.x
Next topic: Migrating EJB references for EJB 1.1 relationships
Related tasks
Migrating Enterprise JavaBeans projects (EJB 1.1 to EJB 2.1)
Converting projects from EJB 1.1 to EJB 2.x
Migrating EJB references for EJB 1.1 relationships
Related reference
Method elements are merged during project structure migration