A P P E N D I X B |
Migrating and Upgrading EJB 1.1 Enterprise Beans |
If you want to use enterprise beans that were built according to the Enterprise JavaBeans Specification version 1.1 (EJB 1.1), you can use the Sun ONE Studio 5 IDE to migrate your beans to the currently supported version (EJB 2.0). Depending on the type of EJB 1.1 enterprise bean and what you want to do with it, the bean might be converted automatically by the IDE. Or, you might have to make some manual changes, which are described in this appendix.
Some of the differences between recent and older versions of the EJB specification involve container-managed persistent (CMP) entity beans, their properties, and the validation of enterprise beans in general. Notice the following points.
In the sections that follow are instructions for updating enterprise beans that were created in the EJB 1.1 environment.
Sometimes you can't recreate a CMP 1.x entity bean from scratch, but you want the bean to be able to use new EJB 2.0 features such as local interfaces, local references, select and home methods. In this case, you will probably need to manually upgrade the bean. Convert it to a CMP 2.x bean as follows:
1. In the Explorer window, create a new Java package.
2. Copy the Java files from the CMP 1.x entity bean's old package. Paste them into the new package (as copies, not as links).
3. Use the EJB Builder Wizard as discussed in Chapter 4 to create a new CMP entity bean.
On the last page of the wizard, specify the copied classes as the bean's remote and home interfaces. Also specify the bean class and primary-key class.
For the moment, ignore the IDE's warning that no CMP (persistent) fields have been found.
4. Add fields as needed and make other edits to correct EJB validation errors.
When you import any other kind of EJB 1.1 enterprise bean into the IDE, the bean is automatically updated to conform to EJB 2.0.
If you try to use new features in an enterprise bean that was created in the EJB 1.1 environment, the results cannot be predicted. Two examples follow.
When you use the product as intended, EJB 1.1 beans have a different contextual menu (the menu that appears in the Explorer window when you right-click the bean's logical node), and the menu options are limited. However, if you choose Customize from the contextual menu, you see a window that seems to allow a local home and a local interface file.
These fields are not editable directly, and the file paths of the local interface do not appear on the property sheet of an EJB 1.1 CMP entity bean.
![]() |
Caution - Do not add local interfaces in this way. If you do, you will not be able to remove the interfaces again. The CMP entity bean will become invalid and cannot be repaired. |
The same caveat applies to local EJB references. They cannot be added to a CMP 1.x entity bean, even though the Customizer window might appear to allow it. If you have done so, you can go to the Customizer window and delete the references you added.
The EJB 2.0 standard is quite large, and its new coding practices are strongly encouraged or enforced by the IDE. If possible, you should recreate your old enterprise beans using the IDE's EJB Builder Wizard. Carefully evaluate your code and upgrade it where necessary to conform to the current EJB standard.
Copyright © 2003, Sun Microsystems, Inc. All rights reserved.