Chapter 17. Enterprise JavaBeans Query Language Syntax

EJB Query Language (EJB QL) was introduced in the EJB 2.0 specification as a scheme for specifying the logic for finder and select methods on EJBs using container-managed persistence (CMP). As described in detail in Chapter 8, the CMP model in EJB 2.0 includes an abstract schema defined around your entity beans and their relationships, where beans become abstract tables, the CMP fields on the beans become abstract columns of sorts, and the relationships between beans act as abstract foreign-key constraints. EJB QL allows you to specify queries based on this abstract schema, to be used by the container in the implementation of finder and select methods for your entity beans.

EJB QL is similar in syntax (naturally) to SQL, but is much simpler since EJB QL needs only to deal with selecting beans and CMP fields from the abstract schema. EJB QL can’t be used to update or delete entity beans (the bean client interfaces are used for that), and it can’t be used to adjust the structure of the abstract schema. “Schema changes” are accomplished using the ejb-jar deployment descriptor: new entity beans are defined, or unneeded ones are removed, and the deployment descriptor is adjusted to include/exclude these beans and define relationships between them. Full details on EJB deployment descriptors can be found in Chapter 10 and examples of their use are shown in Chapter 8.

Basic Structure of EJB QL Queries

EJB QL queries contain three clauses: ...

Get Java Enterprise in a Nutshell, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.