O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required