JPA Query Expressions (JPQL / Criteria)
JPQL and criteria queries are built on query expressions.
Every query consists of clauses, such as SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY. Each clause is composed of JPQL or Criteria API expressions.
Atomic expressions
The atomic query expressions are:
Every query expression consists of at least one atomic component. More complex query expressions are built by combining atomic expressions with operators and functions.
Operators and functions
JPQL and the Criteria API support the following operators, listed in order of decreasing precedence:
- Navigation operator (
.) - Arithmetic operators:
*(multiplication),/(division),+(addition), and-(subtraction) - Comparison operators:
=,<>,<,<=,>,>=,IS [NOT] NULL,[NOT] BETWEEN - Collection operators:
[NOT] IN,IS [NOT] EMPTY,[NOT] MEMBER [OF] - String operator:
[NOT] LIKE - Logical operators:
AND,OR, andNOT
JPA queries also support predefined functions, which this section describes.
Organization of this section
This section contains the following pages:
JPQL LiteralsJPQL Paths and TypesNumbers in JPQLStrings in JPQLDate and Time in JPQLCollections in JPQLComparison OperatorsLogical Operators
Detailed explanations of how to build Criteria API expressions are provided on the following pages:
- Literals and dates (
literal,nullLiteral,currentDate, …) - Paths, navigation, and types (
get,type) - Arithmetic expressions (
sum,diff,prod,quot,mod,abs,neg,sqrt) - String expressions (
like,length,locate,lower,upper,concat,substring, …) - Date and time expressions (
currentDate,currentTime,currentTimestamp) - Collection expressions (
isEmpty,isNotEmpty,isMember,isNotMember,size) - Comparison expressions (
equal,notEqual,gt,ge,lt,le,between,isNull, …) - Logical expressions (
and,or,not,isTrue)