Step 11: Update the Recording Bean

In this step you add a CMP field to the Recording bean to store the rating information collected by the Statistics bean, and change the way tables are created by WebLogic. The tasks in this step are:


To Define a CMP Field

  1. Ensure that the Recording EJB is displayed in Design View.
  2. Right-click the RecordingBean and choose Add CMP field. A CMP field called String field1 appears in the CMP Fields section.
  3. Rename the field String rating. If you step off the field and need to rename it, right-click the field and select Change declaration.

    Note. If you stepped off the field and used Change declaration to rename the field, select the rating declaration in Design View and go to the Property Editor to change the ejbgen:cmp-field tag's column property to rating. (The name of the CMP field and the corresponding column name can be different, but for consistency reasons you should give them the same name here.)

To Change the create-tables Setting

When you first used the Recording bean, WebLogic automatically created the corresponding table with the necessary columns to hold the defined CMP fields, as dictated by the CreateOnly setting in the create-tables property in the Property Editor. This setting does not automatically re-create the table if the definition of CMP fields changes, that is, if you add a new CMP field or change the definition of an existing CMP field. Since you have added an additional CMP field above, you must either manually add the column to the table or tell WebLogic to drop the original table and create a new table. You will do the latter here:

  1. Ensure that the Recording EJB is displayed in Design View.
  2. In the Property Editor, locate the create-tables property under JAR Settings. From the drop-down list choose DropAndCreate. This option will re-create the table whenever the definition of the entity bean no longer matches the table definition. All data stored in the old table will be lost.
  3. Save your results.

To Build the EJBs

  1. Locate the Build window in the IDE. If the Build window is not there, select View-->Windows-->Build.
  2. In the Application pane, right-click MyEJBProject, and select Build MyEJBProject.
  3. Monitor the Build window and verify that the build completes correctly, and that the EJB JAR MyEJBProject.jar is created.
  4. After the build completes, the EJBs are deployed: Watch the green ball in the WebLogic Server status bar at the bottom of WebLogic Workshop turn yellow with the message Updating Server. Wait until the ball turns green again. The two EJBs are now deployed on the server. In addition, the various web applications that were predefined are deployed to the web container. We will turn to these in the next step.
  5. (Optional.) Verify the contents of the EJB JAR. In the Application pane, expand Modules, expand MyEJBProject.jar, and expand the directory structure reflecting the package name. Verify that the bean classes and the various interfaces have been created.

If you encounter a build error related to the ejbgen:ejb-local-ref tag in Statistics bean, make sure that you have specified the Recording bean's name correctly. If you encounter build errors related to the component methods, verify that the methods have been defined correctly. A build error might be followed by a deployment error, in particular for WebAppOne_Standard and related to an unresolved ejb-link. The link cannot be resolved because the EJB JAR was not created. Fixing the build problem should resolve this deployment error. If you encounter deployment errors that seem to be related to one of the web applications, make sure that you build the EJB project and not the entire application (because the application contains page flow applications that have different EJB dependencies from what you have created in this step).

Also, you can compare your code for Statistics Bean and Recording bean with the solution source code located at [BEA_HOME]\weblogic81\samples\platform\tutorial_resources\EJBTutorial\solutions.

Click one of the following arrows to navigate through the tutorial: