Skip Headers

# Using the ejbSelect Method

Previous

Next

The `ejbSelect` method is a query method intended for internal use within an entity bean instance. Specified on the abstract bean itself, the `ejbSelect` method is not directly exposed to the client in the home or component interface. Defined as abstract, each bean can include zero or more such methods.

Select methods have the following characteristics:

- The method name must have `ejbSelect` as its prefix.

- It must be declared as public.

- It must be declared as abstract.

- The `throws` clause must specify the `javax.ejb.FinderException`, although it may also specify application-specific exceptions as well.

- The `result-type-mapping` tag in the `ejb-jar.xml` file determines the return type for `ejbSelect` methods. Set the flag to `Remote` to return `EJBObjects`; set it to `Local` to return `EJBLocalObjects`.

The format for an ejbSelect method definition should be similar to the following:

    public abstract type ejbSelect<METHOD>(...);

The `ejbSelect` query return type is not restricted to the entity bean type on which the `ejbSelect` is invoked. Instead, it can return any type corresponding to a container-managed relationship or container-managed field.

Although the `ejbSelect` method is not based on the identity of the entity bean instance on which it is invoked, it can use the primary key of an entity bean as an argument. This creates a query that is logically scoped to a particular entity bean instance.

To create an ejbSelect method, use this procedure:

1. Update the `ejb-jar.xml` file as follows:

   - Declare the `ejbSelect` method.

   - Enter the EJB QL string in the `ejb-ql` tag.

   - Specify the return type in the `result-type-mapping` tag (if required).

2. Declare the `ejbSelect` on the abstract bean class.

3. Start TopLink Workbench.

4. Click the project icon in the Navigator, and select: Selected > Update Project from ejb-jar.xml to read in the finders.

5. Go the Queries > Named Queries tab for the bean.

6. Select and configure the `ejbSelect` method.