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

WHERE Clause

The WHERE clause of an EJB QL query is used to specify conditional logic that is used to select a subset of the beans references in the FROM clause. Any beans that you want to refer to in your conditional query logic must be declared in the FROM clause of the query.

The syntax of the WHERE clause mirrors the syntax of SQL WHERE clauses. The WHERE clause is made up of literals and variables composed into various conditional expressions. The variables used in a WHERE clause can be query variables declared in the FROM clause, path expressions derived from the query variables, or input parameters provided in the arguments to the corresponding finder or select method. The conditional expressions in the WHERE clause can be composed using arithmetic operators, comparison operators, or logical operators.

Literals

Literals are strings, numeric values, or Boolean values. String literals are enclosed in single quotes:

SELECT OBJECT(p) FROM ProfileBean p WHERE p.name = 'Fred'

If you want to include a single quote in a literal, use two single quotes:

SELECT OBJECT(p) FROM ProfileBean p WHERE p.name = 'Fred''s profile'

Numeric literals can be either exact integer values or approximate floating-point values. Integer values are specified using a sequence of digits with no decimal point:

SELECT OBJECT(prof) FROM ProfileBean prof WHERE prof.id < 1000

Floating-point values are specified using either scientific notation or a numeric value with a decimal point:

SELECT OBJECT(p) FROM Person p WHERE ...

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