background image

Expression Types

<< Path Expressions | WHERE Clause >>
<< Path Expressions | WHERE Clause >>

Expression Types

SELECT DISTINCT p
FROM Player p
WHERE p.salary BETWEEN :lowerSalary AND :higherSalary
Here, the WHERE clause also contains a single_valued_path_expression. The t is an
identification variable, league is a single-valued relationship field, and sport is a persistent
field of league.
SELECT DISTINCT p
FROM Player p, IN (p.teams) t
WHERE t.league.sport = :sport
Here, the WHERE clause contains a collection_valued_path_expression. The p is an
identification variable, and teams designates a collection-valued relationship field.
SELECT DISTINCT p
FROM Player p
WHERE p.teams IS EMPTY
Expression Types
The type of a path expression is the type of the object represented by the ending element, which
can be one of the following:
Persistent field
Single-valued relationship field
Collection-valued relationship field
For example, the type of the expression p.salary is double because the terminating persistent
field (salary) is a double.
In the expression p.teams, the terminating element is a collection-valued relationship field
(teams). This expression's type is a collection of the abstract schema type named Team. Because
Team
is the abstract schema name for the Team entity, this type maps to the entity. For more
information on the type mapping of abstract schemas, see the section
"Return Types" on
page 759
.
Navigation
A path expression enables the query to navigate to related entities. The terminating elements of
an expression determine whether navigation is allowed. If an expression contains a
single-valued relationship field, the navigation can continue to an object that is related to the
field. However, an expression cannot navigate beyond a persistent field or a collection-valued
relationship field. For example, the expression p.teams.league.sport is illegal, because teams
is a collection-valued relationship field. To reach the sport field, the FROM clause could define an
identification variable named t for the teams field:
Full Query Language Syntax
The Java EE 5 Tutorial · September 2007
750