JPA Query Expressions (JPQL / Criteria)
Query expressions are the foundations on which JPQL and criteria queries are built.
Every query consists of clauses - SELECT, FROM, WHERE, GROUP BY, HAVING and ORDER BY, and each clause consists of JPQL / Criteria query 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 / Criteria queries support the following operators (in order of decreasing precedence):
- Navigation operator (.)
- Arithmetic operators:
*
(multiplication),/
(division), + (addition) and-
(subtraction). - Comparison operators:
=, <>, <, <=,>, >=, IS [NOT] NULL, [NOT] BETWEEN,
including Collection operators: [NOT] IN, IS [NOT] EMPTY, [NOT] MEMBER [OF]
and the [NOT] LIKE operator. - Logical operators: AND, OR, NOT.
In addition, JPA queries support predefined functions, which are also described in this section.
Organization of this Section
This section contains the following pages:
- Literals in JPQL and Criteria Queries
- Paths and Types in JPQL and Criteria API
- Numbers in JPQL and Criteria Queries
- Strings in JPQL and Criteria Queries
- Date and Time in JPQL and Criteria Queries
- Collections in JPQL and Criteria Queries
- Comparison in JPQL and Criteria API
- Logical Operators in JPQL and Criteria API
Detailed explanations on how to build criteria query expressions are provided as follows:
- 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, ...
). - Data 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
).