Step 2: Adding an addDepartment() method to the Session Bean

Previous topic
Previous
Next topic
Next

Now that your Dept entity ejb has a new create method, you'll want to call that from the session bean facade.

To add the create() method to the session facade:

  1. In the UML diagram, click below listDepartments() to add a new method.
  2. Type addDepartment(Long deptno, String dname, Long location) : void
  3. In the Navigator, double-click hrAppBean.java to open it in the Code Editor.
  4. Add the following to the import block:
    import javax.ejb.CreateException;
  5. In the Structure pane, double-click addDepartment() to jump to that method in the code.
  6. Paste in the following code in place of the stub method:

  7.   public void addDepartment(Long deptno, String dname, Long location)
      {
      try {
        this.getDeptLocalHome().create(deptno,dname,location);
       }
       catch(NamingException ne)
        {
    	System.out.println(ne.toString());
    	throw new javax.ejb.EJBException(ne);
        }
        catch(CreateException ce)
        {
    	System.out.println(ce.toString());
    	throw new javax.ejb.EJBException(ce);
        }
      
      }