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

Migrating the Bean Class

This section describes the steps required to migrate the bean class to Application Server 8.2.

ProcedureTo Migrate the Bean Class

  1. Prepend the bean class declaration with the keyword abstract.

    For example if the bean class declaration was:

    public class CabinBean implements EntityBean

    change it to:

    abstract public class CabinBean implements EntityBean
  2. Prefix the accessors with the keyword abstract.

  3. Insert all the accessors after modification into the source(.java) file of the bean class at class level.

  4. Comment out all the cmp fields in the source file of the bean class.

  5. Construct protected instance variable declarations from the cmp-field names in lowercase and insert them at the class level.

  6. Read up all the ejbCreate() method bodies (there could be more than one ejbCreate).

    Look for the pattern ”<cmp-field>=some value or local variable’, and replace it with the expression, abstract mutator method name (same value or local variable).

    For example, if the ejbCreate body before migration is:

    public MyPK ejbCreate(int id, String name) { = 10*id;
       Name = name;   //1
       return null;

    Change it to:

    public MyPK ejbCreate(int id, String name) {
       setName(name);   //1
       return null;

    Note that the method signature of the abstract accessor in //1 is as per the Camel Case convention mandated by the EJB 2.0 specification. Also, the keyword this may or may not be present in the original source, but it must be removed from the modified source file.

  7. Initialize all the protected variables declared in the ejbPostCreate()methods in step 5.

    The protected variables will be equal in number with the ejbCreate() methods. This initialization will be done by inserting the initialization code in the following manner:

    protected String name;  //from step 5
    protected int id;  //from step 5
    public void ejbPostCreate(int id, String name) {
       name = getName();    /*abstract accessor*/ //inserted in this step
       id  = getId();        /*abstract accessor*/ //inserted in this step
  8. Inside the ejbLoad method, set the protected variables to the beans’ database state.

    To do so, insert the following lines of code:

    public void ejbLoad() {
       name = getName();    // inserted in this step
       id = getId();        // inserted in this step
       ...                  // existing code
  9. Similarly, update the bean's state inside ejbStore()so that its database state gets updated.

    But remember, you are not allowed to update the setters that correspond to the primary key outside the ejbCreate(), so do not include them inside this method. Insert the following lines of code:

    public void ejbStore() {
        setName(name);       //inserted in this step
        setId(id);           //Do not insert this if
                             //it is a part of the
                             //primary key.
        ...                  //already present code
  10. Replace all occurrences of any <cmp-field> variable names with the equivalent protected variable name (as declared in step 5).

    If you do not migrate the bean, at the minimum you need to insert the <cmp-version>1.x</cmp-version> tag inside the ejb-jar.xml file at the appropriate place, so that the unmigrated bean still works on Application Server 8.2.