background image

Collection Member Declarations

<< Identification Variables | Path Expressions >>
<< Identification Variables | Path Expressions >>

Collection Member Declarations

FROM Player p
A range variable declaration can include the optional AS operator:
FROM Player AS p
In most cases, to obtain objects a query uses path expressions to navigate through the
relationships. But for those objects that cannot be obtained by navigation, you can use a range
variable declaration to designate a starting point (or root).
If the query compares multiple values of the same abstract schema type, then the FROM clause
must declare multiple identification variables for the abstract schema:
FROM Player p1, Player p2
For a sample of such a query, see
"Comparison Operators" on page 739
.
Collection Member Declarations
In a one-to-many relationship, the multiple side consists of a collection of entities. An
identification variable can represent a member of this collection. To access a collection
member, the path expression in the variable's declaration navigates through the relationships in
the abstract schema. (For more information on path expressions, see the following section.)
Because a path expression can be based on another path expression, the navigation can traverse
several relationships. See
"Traversing Multiple Relationships" on page 737
.
A collection member declaration must include the IN operator, but it can omit the optional AS
operator.
In the following example, the entity represented by the abstract schema named Player has a
relationship field called teams. The identification variable called t represents a single member
of the teams collection.
FROM Player p, IN (p.tea
ms) t
Joins
The JOIN operator is used to traverse over relationships between entities, and is functionally
similar to the IN operator.
In the following example, the query joins over the relationship between customers and orders:
SELECT c
FROM Customer c JOIN c.orders o
WHERE c.status = 1 AND o.totalPrice > 10000
The INNER keyword is optional:
Full Query Language Syntax
The Java EE 5 Tutorial · September 2007
748