Step 1: Adding a Create Method to the Entity Bean
|

Previous |

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:
- In the Navigator, double-click Dept to open
the EJB Module Editor.
- Expand the node for Dept and click the Methods
node.
- In the Method Category list, choose Create methods.
- Click Add.
- In the Method Details dialog box, in the Parameters field, type the following:
Long deptno, String dname, Long location
- Click OK to close the dialog.
Your new create() method appears in the list of
methods.
- Click OK to close the EJB Module Editor.
To add code to the Dept entity bean:
- In the Navigator, expand the node for the Dept bean and double-click DeptBean.java
- In the Structure pane, double-click ejbCreate(Long,
String, Long) to jump to that method in the code.
- 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;
}
- In the Navigator, right click DeptBean.java
and choose Make DeptBean.java to make sure it
compiles without errors.