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 EJB Methods > Add
Finder Method.
- In the New Finder Method dialog box, define the method signature:
- Add text to the base findBy name of the method.
- 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.
- Specify which interfaces to add the method to (remote and/or local).
- Specify any parameters that the method needs.
- 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 IDE adds 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 Details
view.
- Expand the entity bean's header and the CMP Finder Methods header. The table
lists all of the existing CMP finder methods.
- Click Add or Edit to make changes to the list finder methods.
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 both a enterprise bean, do one of the
following:
- Delete the method from the bean's Home Methods list in the Projects
window.
- Delete the method from the CMP Finder Methods header in the ejb-jar.xml
graphical editor.
If you delete the finder method in the Source Editor, the IDE does not remove
it from the bean interfaces.
- 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