FROM Clause
The FROM
clause in an
EJB QL query declares the subset of elements from the abstract schema
that is the target of the query. Any elements referenced in the
conditional expressions in the WHERE
clause as well as the element that is
specified as the return type in the SELECT
clause must be included in the
FROM
clause declarations.
The FROM
clause is made up of
a list of variable declarations. Each variable is declared with a type
and a unique variable name. Variable names can be any valid Java
identifier. The types of the variables are taken from the abstract
schema elements defined by the entity EJBs. These variables are
declared as either range variables or
collection member variables.
Range Variables
Range variables are query variables that take the type of one
of the entity EJBs in your abstract schema. They are called range
variables because their actual value can range over any of the
actual entities present in the persistent store at the time that the
query is executed (limited by the conditions in the WHERE
clause, if present). For example, we
used the following EJB QL query for one of the finder methods on our Profile
EJB in Chapter 6:
SELECT OBJECT(p) FROM ProfileBean p WHERE p.entriesBytes IS NULL
In this query, the FROM
clause declares a single range variable, p
, and it’s declared to range over the EJB
type ProfileBean
. ProfileBean
is the abstract schema type
that we declared for our Profile
EJB. This is analogous to declaring a query variable in SQL that ranges ...
Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.