Step 1: Adding a Create Method to the Entity Bean

Previous topic
Previous
Next topic
Next

The first step is to add a new create() method on the Dept entity bean. The Dept bean already has a create() method that accepts two parameters, a department name and a department number. Your new create() method will take an additional parameter, the department location.

To add a new create() method:

  1. In the Navigator, double-click Dept to open the EJB Module Editor.
  2. Expand the node for Dept and click the Methods node.
  3. In the Method Category list, choose Create methods.
  4. Click Add.
  5. In the Method Details dialog box, in the Parameters field, type the following:
    Long deptno, String dname, Long location
  6. Click OK to close the dialog.
    Your new create() method appears in the list of methods.
  7. Click OK to close the EJB Module Editor.

To add code to the Dept entity bean:

  1. In the Navigator, expand the node for the Dept bean and double-click DeptBean.java
  2. In the Structure pane, double-click ejbCreate(Long, String, Long) to jump to that method in the code.
  3. Replace the stub method with the following code:
    public Long ejbCreate(Long deptno, String dname, Long location)
    {
      this.setDepartment_id(deptno);
      this.setDepartment_name(dname);
      this.setLocation_id(location);
      return deptno;
    }
    
  4. In the Navigator, right click DeptBean.java and choose Make DeptBean.java to make sure it compiles without errors.