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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access