Defining a Finder Method

See Also

A finder method is a type of query method that is used in an EJB 2.1 entity bean. (Select methods are the other type of query method.) Finder methods are unique to entity beans because entity beans represent data in a database that can be identified and found. Session beans do not represent database data and therefore do not have data that can be found.

To define a finder method for an entity bean:

  1. Open the bean class in the Source Editor.
  2. Right-click anywhere in the Source Editor and choose Insert Code > Add Finder Method.
  3. In the Add Finder Method dialog box, define the method signature:
    1. Add text to the base findBy name of the method.
    2. Specify any parameters that the method needs.
    3. Specify which interfaces to add the method to (remote and/or local).
    4. Specify the return cardinality for the method. This setting should match the return cardinality of the statement in the database. If you select One, the statement returns the bean's interface. If you select Many, the statement returns a java.util.Collection object.
    5. If the bean uses container-managed persistence (CMP), enter the EJB QL statement that the method will use to find the enterprise bean or beans that the method is to return.
  4. Click OK to create the method.

    The IDE adds the method signature to the bean's interfaces and registers the method in the general deployment descriptor.

To view, edit, or delete existing finder methods:

  1. In the Projects window, expand the Configuration Files node for your EJB module project.
  2. Double-click ejb-jar.xml. The graphical editor opens in the General view.
  3. Click the XML tab and make your changes in the XML editor.

Notes:

See Also
About Entity Beans
Defining a Select Method
Defining a Business Method
Defining a CMP Field
Adding EJB QL to a Finder or Select Method
Generating CMP Entity Beans from a Database

Legal Notices