Use EJB query
The EJB query language is used to specify a query over container-managed entity beans. The language is similar to structured query language (SQL). An EJB query is independent of the bean's mapping to a persistent store.
Overview
An EJB query can be used in three situations:
- To define a finder method of an EJB entity bean.
- To define a select method of an EJB entity bean.
- To dynamically specify a query using the executeQuery() dynamic API.
Finder and select queries are specified in the bean's deployment descriptor using the <ejb-ql> tag; they are compiled into SQL during deployment. Dynamic queries are included within the application code itself.
WebSphere Application Server's EJB query language is compliant with the EJB QL defined in Sun's EJB 2.1 specification and has additional capabilities as listed in the topic Comparison of EJB 2.x specification and WebSphere Query Language.
Procedure
- Before using EJB query, familiarize yourself with query language concepts, starting with the topic, EJB Query Language.
- Define an EJB query in one of the following ways:
- Application Server Toolkit. When defining an EJB 2.1 entity bean in an EJB deployment descriptor editor, on the Beans page click Add under Queries and, in the Add Finder Descriptor wizard, define a find or ejbSelect method. See the online Application Server Toolkit information for documentation on wizard options.
- Rational Application Developer. When defining an entity bean, specify the <ejb-ql> tag for the finder or select method.
- Dynamic query service. Add the executeQuery() method to your application.
Example
See the topic Example: EJB queries.
EJB query language
Use the dynamic query service