EJB QL is expressed in terms of the abstract persistence schema of an entity bean: its abstract schema name, CMP fields, and CMR fields. EJB QL uses the abstract schema names to identify beans, the CMP fields to specify values, and the CMR fields to navigate across relationships.
To discuss EJB QL, we will make use of the relationships among the Customer, Address, CreditCard, Cruise, Ship, Reservation, and Cabin EJBs defined in Chapter 7. Figure 8-1 is a class diagram that shows the direction and cardinality (multiplicity) of the relationships among these beans.
Figure 8-1. Titan Cruises class diagram
The simplest EJB QL statement has no
WHERE clause and only one abstract schema type.
For example, you could define a query method to select all Customer
SELECT OBJECT( c ) FROM Customer AS c
clause determines which entity bean
types will be included in the select statement (i.e., provides the
of the select). In this case, the
declares the type to be
Customer, which is the
abstract schema name of the Customer EJB. The
c part of the clause assigns
c as the identifier of the Customer EJB. This is similar to SQL, which allows an identifier to be associated with a table. Identifiers can be any length and follow the same rules that are applied to field names in the Java programming language. However, identifiers cannot ...