You can add "find" or "ejbSelect" finder methods to the home interfaces
of EJB 2.x CMP beans. The finder methods use the EJB query language. A wizard
guides you through the steps for adding new or existing finders to your bean.
The EJB query language (EJB QL) syntax is based on SQL and allows
searches on the persistent attributes of an enterprise bean and associated
bean attributes. The query language is independent of the bean's mapping to
a relational datastore and it is portable. The query language is compiled
into SQL at deployment time based on the schema mapping for the bean.
For
details on EJB QL, go to the WebSphere Application Server Information Center and
search for the keywords "EJB QL".
To add an EJB QL query to an EJB 2.x
enterprise bean:
- In the Project Explorer view of the J2EE perspective, right-click
the Deployment Descriptor for your EJB project and select to
open the deployment descriptor editor.
- On the Bean page of the editor, select the EJB 2.x CMP entity bean
that you want to add a finder method to.
- Scroll to the Queries section, and click Add.
The Add Finder Descriptor wizard opens.
- Select one of the following options:
- New - creates a new finder method.
- Existing - uses an existing finder method.
- Select a method type from the following choices:
- find Method - Finder methods are defined in
the home interfaces (local, remote, or both) of entity beans. The return and
result of the finder method depends on where it defined.
- ejbSelect method - ejbSelect methods are special
query methods not directly exposed through the client view. ejbSelect methods
are typically used to select the persistent state of an entity, or to select
entities that are related to the entity bean for which the query is defined.
- If you are using an existing finder, select from a list of finders
that were discovered, then click Finish.
- If you are defining a new finder, complete the following steps.
- For the type of finder, select at least one of the following check
boxes:
- Local - Select to add the method declaration
to the local home interface for local method calls.
- Remote - Select to add the method declaration
to the remote home interface for remote method calls.
You can select both check boxes to include the finder in both remote
and local interfaces. The check box will only be available if your bean includes
the respective interface.
- Optional: If you are creating an ejbSelect method,
you can select the Return remote entities check box. This option indicates
that you want remote references returned. This option is only available with
this method type.
- In the Name field, type a name for the new
query. Query method names must begin with the letters indicating the type
selected, for example find or ejbSelect.
- Optional: Click Add to add a
method parameter.
- In the Return type drop-down list, select
the type that the finder method will return.
- Click Next. The Bean, Abstract
schema name, and Query method name fields
are read-only.
- Optional: Type a description for your method in the Description text
area.
- Optional: To help you generate your EJB query, you
can start with a sample query in the Select a sample query drop
down list.
- Type or modify your query in the Query statement text
area.
- Click Finish.
A <query></query> element is added to the deployment
descriptor for the bean. The actual query is added to the <ejb-ql></ejb-ql> element.
The method declaration is added to the home interface (local, remote, or both,
depending on your selections).
To edit or remove the query, select the query in the Queries section
and click Edit or Remove.