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:
- Open the bean class in the Source Editor.
- Right-click anywhere in the Source Editor and choose Insert Code > Add
Finder Method.
- In the Add Finder Method dialog box, define the method signature:
- Add text to the base findBy name of the method.
- Specify any parameters that the method needs.
- Specify which interfaces to add the method to (remote and/or local).
- 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.
- 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.
- 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.
- If the entity bean uses CMP, you are done. The container
implements the finder method from the signature in the home interface
or local home interface, so the home interface and the local home interface
are the only places the method appears.
- If the entity bean uses bean-managed persistence (BMP), the IDE adds
an empty ejbFindyourname method to the bean class so you
can implement the method. You must implement the ejbFindyourname
method yourself.
To view, edit, or delete existing finder methods:
- In the Projects window, expand the Configuration Files node for your EJB
module project.
- Double-click ejb-jar.xml. The graphical editor opens in the General view.
- Click the XML tab and make your changes in the XML editor.
- If you make changes to ejb-jar.xml you will
also need to make corresponding changes in your bean source code.
Notes:
- When the IDE adds a finder method to an entity bean, it does not save
the bean class or the bean interfaces. Only when you compile or save the project
are the changes saved to disk.
- To fully remove a finder method from an enterprise bean, do the following:
- Delete the method from the bean's source code.
- Delete the finder query from ejb-jar.xml.
- 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