Step 1: Creating a Finder Method

Previous topic
Previous
Next topic
Next

The first step is to create a new finder method in the Dept entity bean. While you could create this method on the UML diagram, this time you'll use the EJB Module Editor so that you can become familiar with this tool.

To create a new finder method:

  1. In the Navigator, double-click the Dept entity bean.
    The EJB Module Editor opens.
  2. In the EJB Module Editor, expand the Dept node and click Methods.
  3. In the Method Category, select Finder Methods.
  4. Click Add.
    The Method Details dialog opens.
  5. In the Method Details dialog, change the Name to findByDname
  6. In the Return Type field, type DeptLocal.
  7. In the Parameters field, type String dname
  8. On the bottom of the dialog, click the EJB QL tab.
  9. Paste in the following code:
    select distinct object (d) 
    from Dept d
    where d.department_name = ?1
  10. Click OK to close the dialog.
  11. In the EJB Module Editor, click Preview XML.
    Notice the query tag that was added.
  12. Click OK to close the EJB Module Editor.