provides a more flexible method to query the database than
find methods. Find methods belong to a home interface and only return
the corresponding local object. A
can only return a
return any type in the database or a collection of database objects. They
are restricted to the entity bean implementation class; you'll need to write
a separate business method to expose the results of the query.
Like find methods,
methods use the deployment descriptor
to define the EJB-QL query. Resin-CMP will generate the appropriate SQL
for the select.
method for the example is in
class. There are no real limitations on which
bean implemenation has the
method. All the entity beans in the database are accessible.
methods are not visible in either the home or the
local interfaces. If the bean needs to make the results visible,
you'll need to create a business method to collect and return the
Unlike the find methods, ejbSelect needs an abstract method in the bean implementation. Finds declare the find method in the home interface; selects declare the ejbSelect method in the bean implementation.
The select query is defined in the deployment descriptor like the find query. The following is the query for the example.
The required SELECT clause may return any cmp-field or cmr-field or any
collection of either. In this case we'll return a collection of
strings. This return value would be illegal in a find method because
a find method could only return
couldn't return the
interface from a
The required FROM clause defines the abstract tables, traversing relations as necessary. In this case, we define the variable to range over all the students in the house. All collection-valued relations will use IN expressions to define a query variables.
The optional WHERE clause can use normal expressions like '=' or
boolean expressions. WHERE can use
arguments with the '?1'
The optional ORDER BY clause is a Resin-CMP extension to EJB-QL. It orders the select so the boys will be listed alphabetically. Because the ORDER BY clause is so useful, a future version of the EJB 2.0 spec will certainly include it.