CriteriaBuilder
Used to construct criteria queries, compound selections, expressions, predicates, orderings.
Note that Predicate is used instead of Expression<Boolean> in this API in order to work around the fact that Java generics are not compatible with varags.
- Since:
- JPA 2.0
The JPA Criteria API Queries article explains how to use
CriteriaBuilder.Public Methods
- Parameters:
x- expression
- Return:
- absolute value
- Since:
- JPA 2.0
- Parameters:
subquery- subquery
- Return:
- all expression
- Since:
- JPA 2.0
- Parameters:
x- boolean expressiony- boolean expression
- Return:
- and predicate
- Since:
- JPA 2.0
A conjunction of zero predicates is true.
- Parameters:
restrictions- a list of zero or more restriction predicates
- Return:
- and predicate
- Since:
- JPA 3.2
A conjunction of zero predicates is true.
- Parameters:
restrictions- zero or more restriction predicates
- Return:
- and predicate
- Since:
- JPA 2.0
This expression is equivalent to a
some expression. - Parameters:
subquery- subquery
- Return:
- any expression
- Since:
- JPA 2.0
- Parameters:
selections- list of selection items
- Return:
- array-valued compound selection
- Throws:
- IllegalArgumentException - if an argument is a tuple- or array-valued selection item
- Since:
- JPA 3.2
- Parameters:
selections- selection items
- Return:
- array-valued compound selection
- Throws:
- IllegalArgumentException - if an argument is a tuple- or array-valued selection item
- Since:
- JPA 2.0
- Parameters:
expression- expression used to define the ordering
- Return:
- ascending ordering corresponding to the expression
- Since:
- JPA 2.0
- Parameters:
expression- expression used to define the orderingnullPrecedence- the precedence of null values
- Return:
- ascending ordering corresponding to the expression
- Since:
- JPA 3.2
- Parameters:
x- expression representing input value to avg operation
- Return:
- avg expression
- Since:
- JPA 2.0
- Parameters:
v- expressionx- expressiony- expression
- Return:
- between predicate
- Since:
- JPA 2.0
- Parameters:
v- expressionx- valuey- value
- Return:
- between predicate
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- ceiling
- Since:
- JPA 2.0
CriteriaBuilder.Coalesce<T> coalesce()
- Return:
- coalesce expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- coalesce expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- coalesce expression
- Since:
- JPA 2.0
- Parameters:
x- string expressiony- string expression
- Return:
- expression corresponding to concatenation
- Since:
- JPA 2.0
- Parameters:
x- string expressiony- string
- Return:
- expression corresponding to concatenation
- Since:
- JPA 2.0
If the given list of expressions is empty, returns an expression equivalent to
literal(""). - Parameters:
expressions- string expressions
- Return:
- expression corresponding to concatenation
- Since:
- JPA 2.0
- Parameters:
x- stringy- string expression
- Return:
- expression corresponding to concatenation
- Since:
- JPA 2.0
A conjunction with zero conjuncts is true.
- Return:
- and predicate
- Since:
- JPA 2.0
This method is used to specify a constructor that is applied to the results of the query execution. If the constructor is for an entity class, the resulting entities will be in the new state after the query is executed.
- Parameters:
resultClass- class whose instance is to be constructedselections- arguments to the constructor
- Return:
- compound selection item
- Throws:
- IllegalArgumentException - if an argument is a tuple- or array-valued selection item
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to count operation
- Return:
- count expression
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to count distinct operation
- Return:
- count distinct expression
- Since:
- JPA 2.0
- Parameters:
targetEntity- target type for delete operation
- Return:
- the query object
- Since:
- JPA 2.1
- Parameters:
targetEntity- target type for update operation
- Return:
- the query object
- Since:
- JPA 2.1
- Return:
- criteria query object
- Since:
- JPA 2.0
- Parameters:
resultClass- type of the query result
- Return:
- criteria query object
- Since:
- JPA 2.0
- Return:
- criteria query object
- Since:
- JPA 2.0
- Return:
- expression for current date
- Since:
- JPA 2.0
- Return:
- expression for current time
- Since:
- JPA 2.0
- Return:
- expression for current timestamp
- Since:
- JPA 2.0
- Parameters:
expression- expression used to define the ordering
- Return:
- descending ordering corresponding to the expression
- Since:
- JPA 2.0
- Parameters:
expression- expression used to define the orderingnullPrecedence- the precedence of null values
- Return:
- descending ordering corresponding to the expression
- Since:
- JPA 3.2
- Parameters:
x- expressiony- expression
- Return:
- difference
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- difference
- Since:
- JPA 2.0
- Parameters:
x- valuey- expression
- Return:
- difference
- Since:
- JPA 2.0
A disjunction with zero disjuncts is false.
- Return:
- or predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- equality predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- object
- Return:
- equality predicate
- Since:
- JPA 2.0
- Return:
- a new criteria query which returns the result of subtracting the results of the second query from the results of the first query
- Since:
- JPA 3.2
- Return:
- a new criteria query which returns the result of subtracting the results of the second query from the results of the first query
- Since:
- JPA 3.2
- Parameters:
subquery- subquery whose result is to be tested
- Return:
- exists predicate
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- exponential
- Since:
- JPA 2.0
- Parameters:
field- a temporal field typetemporal- a date, time, or datetime
- Return:
- expression for the value of the extracted field
- Since:
- JPA 3.2
- Parameters:
x- expression
- Return:
- floor
- Since:
- JPA 2.0
- Parameters:
name- function nametype- expected result typeargs- function arguments
- Return:
- expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- greater-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- greater-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- greater-than predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- greater-than predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- greater-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- greater-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to greatest operation
- Return:
- greatest expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- greater-than predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- greater-than predicate
- Since:
- JPA 2.0
CriteriaBuilder.In<T> in(Expression<?extendsT> expression)
- Parameters:
expression- to be tested against list of values
- Return:
- in predicate
- Since:
- JPA 2.0
- Return:
- a new criteria query which returns the intersection of the results of the given queries
- Since:
- JPA 3.2
- Return:
- a new criteria query which returns the intersection of the results of the given queries
- Since:
- JPA 3.2
- Parameters:
collection- expression
- Return:
- is-empty predicate
- Since:
- JPA 2.0
- Parameters:
x- expression to be tested
- Return:
- predicate
- Since:
- JPA 2.0
If the collection is empty, the predicate will be false.
- Parameters:
elem- elementcollection- expression
- Return:
- is-member predicate
- Since:
- JPA 2.0
If the collection is empty, the predicate will be false.
- Parameters:
elem- element expressioncollection- expression
- Return:
- is-member predicate
- Since:
- JPA 2.0
- Parameters:
collection- expression
- Return:
- is-not-empty predicate
- Since:
- JPA 2.0
If the collection is empty, the predicate will be true.
- Parameters:
elem- elementcollection- expression
- Return:
- is-not-member predicate
- Since:
- JPA 2.0
If the collection is empty, the predicate will be true.
- Parameters:
elem- element expressioncollection- expression
- Return:
- is-not-member predicate
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- is-not-null predicate
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- is-null predicate
- Since:
- JPA 2.0
- Parameters:
x- expression to be tested
- Return:
- predicate
- Since:
- JPA 2.0
- Parameters:
map- map
- Return:
- set expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- less-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- less-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to least operation
- Return:
- least expression
- Since:
- JPA 2.0
- Parameters:
x- string expressionlen- length of the substring to return
- Return:
- expression for the leftmost substring
- Since:
- JPA 2.0
- Parameters:
x- string expressionlen- length of the substring to return
- Return:
- expression for the leftmost substring
- Since:
- JPA 2.0
- Parameters:
x- string expression
- Return:
- length expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- less-than predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- less-than predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- less-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- less-than-or-equal predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- string expression
- Return:
- like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- string expressionescapeChar- escape character expression
- Return:
- like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- string expressionescapeChar- escape character
- Return:
- like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- string
- Return:
- like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- stringescapeChar- escape character expression
- Return:
- like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- stringescapeChar- escape character
- Return:
- like predicate
- Since:
- JPA 2.0
- Parameters:
value- value represented by the expression
- Return:
- expression literal
- Throws:
- IllegalArgumentException - if value is null
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- natural logarithm
- Since:
- JPA 2.0
- Return:
- expression for current date
- Since:
- JPA 2.0
- Return:
- expression for current timestamp
- Since:
- JPA 2.0
- Return:
- expression for current time
- Since:
- JPA 2.0
The first position in a string is denoted by 1. If the string to be located is not found, 0 is returned.
Warning: the order of the parameters of this method is reversed compared to the corresponding function in JPQL.
- Parameters:
x- expression for string to be searchedpattern- expression for string to be located
- Return:
- expression corresponding to position
- Since:
- JPA 2.0
Expression<Integer> locate(Expression<String> x, Expression<String> pattern, Expression<Integer> from)
The first position in a string is denoted by 1. If the string to be located is not found, 0 is returned.
Warning: the order of the first two parameters of this method is reversed compared to the corresponding function in JPQL.
- Parameters:
x- expression for string to be searchedpattern- expression for string to be locatedfrom- expression for position at which to start search
- Return:
- expression corresponding to position
- Since:
- JPA 2.0
The first position in a string is denoted by 1. If the string to be located is not found, 0 is returned.
Warning: the order of the parameters of this method is reversed compared to the corresponding function in JPQL.
- Parameters:
x- expression for string to be searchedpattern- string to be located
- Return:
- expression corresponding to position
- Since:
- JPA 2.0
The first position in a string is denoted by 1. If the string to be located is not found, 0 is returned.
Warning: the order of the first two parameters of this method is reversed compared to the corresponding function in JPQL.
- Parameters:
x- expression for string to be searchedpattern- string to be locatedfrom- position at which to start search
- Return:
- expression corresponding to position
- Since:
- JPA 2.0
- Parameters:
x- string expression
- Return:
- expression to convert to lowercase
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- less-than predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- less-than predicate
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to max operation
- Return:
- max expression
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to min operation
- Return:
- min expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- modulus
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- modulus
- Since:
- JPA 2.0
- Parameters:
x- valuey- expression
- Return:
- modulus
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- arithmetic negation
- Since:
- JPA 2.0
- Parameters:
restriction- restriction expression
- Return:
- not predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- inequality predicate
- Since:
- JPA 2.0
- Parameters:
x- expressiony- object
- Return:
- inequality predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- string expression
- Return:
- not-like predicate
- Since:
- JPA 2.0
Predicate notLike(Expression<String> x, Expression<String> pattern, Expression<Character> escapeChar)
- Parameters:
x- string expressionpattern- string expressionescapeChar- escape character expression
- Return:
- not-like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- string expressionescapeChar- escape character
- Return:
- not-like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- string
- Return:
- not-like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- stringescapeChar- escape character expression
- Return:
- not-like predicate
- Since:
- JPA 2.0
- Parameters:
x- string expressionpattern- stringescapeChar- escape character
- Return:
- not-like predicate
- Since:
- JPA 2.0
- Parameters:
resultClass- type of the null literal
- Return:
- null expression literal
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- nullif expression
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- nullif expression
- Since:
- JPA 2.0
- Parameters:
x- boolean expressiony- boolean expression
- Return:
- or predicate
- Since:
- JPA 2.0
A disjunction of zero predicates is false.
- Parameters:
restrictions- a list of zero or more restriction predicates
- Return:
- or predicate
- Since:
- JPA 3.2
A disjunction of zero predicates is false.
- Parameters:
restrictions- zero or more restriction predicates
- Return:
- or predicate
- Since:
- JPA 2.0
- Parameters:
paramClass- parameter class
- Return:
- parameter expression
- Since:
- JPA 2.0
- Parameters:
paramClass- parameter classname- name that can be used to refer to the parameter
- Return:
- parameter expression
- Since:
- JPA 2.0
- Parameters:
x- basey- exponent
- Return:
- the base raised to the power of the exponent
- Since:
- JPA 2.0
- Parameters:
x- basey- exponent
- Return:
- the base raised to the power of the exponent
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- product
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- product
- Since:
- JPA 2.0
- Parameters:
x- valuey- expression
- Return:
- product
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- quotient
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- quotient
- Since:
- JPA 2.0
- Parameters:
x- valuey- expression
- Return:
- quotient
- Since:
- JPA 2.0
Expression<String> replace(Expression<String> x, Expression<String> substring, Expression<String> replacement)
- Parameters:
x- string expressionsubstring- the literal substring to replacereplacement- the replacement string
- Return:
- expression for the resulting string
- Since:
- JPA 2.0
- Parameters:
x- string expressionsubstring- the literal substring to replacereplacement- the replacement string
- Return:
- expression for the resulting string
- Since:
- JPA 2.0
- Parameters:
x- string expressionsubstring- the literal substring to replacereplacement- the replacement string
- Return:
- expression for the resulting string
- Since:
- JPA 2.0
- Parameters:
x- string expressionsubstring- the literal substring to replacereplacement- the replacement string
- Return:
- expression for the resulting string
- Since:
- JPA 2.0
- Parameters:
x- string expressionlen- length of the substring to return
- Return:
- expression for the rightmost substring
- Since:
- JPA 2.0
- Parameters:
x- string expressionlen- length of the substring to return
- Return:
- expression for the rightmost substring
- Since:
- JPA 2.0
- Parameters:
x- basen- number of decimal places
- Return:
- the rounded value
- Since:
- JPA 2.0
CriteriaBuilder.Case<R> selectCase()
- Return:
- general case expression
- Since:
- JPA 2.0
CriteriaBuilder.SimpleCase<C,R> selectCase(Expression<?extendsC> expression)
- Parameters:
expression- to be tested against the case conditions
- Return:
- simple case expression
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- sign
- Since:
- JPA 2.0
- Parameters:
collection- collection
- Return:
- size expression
- Since:
- JPA 2.0
- Parameters:
collection- expression
- Return:
- size expression
- Since:
- JPA 2.0
This expression is equivalent to an
any expression. - Parameters:
subquery- subquery
- Return:
- some expression
- Since:
- JPA 2.0
- Parameters:
x- expression
- Return:
- square root
- Since:
- JPA 2.0
Extracts a substring starting at the specified position through to end of the string. First position is 1.
- Parameters:
x- string expressionfrom- start position expression
- Return:
- expression corresponding to substring extraction
- Since:
- JPA 2.0
Expression<String> substring(Expression<String> x, Expression<Integer> from, Expression<Integer> len)
Extracts a substring of given length starting at the specified position. First position is 1.
- Parameters:
x- string expressionfrom- start position expressionlen- length expression
- Return:
- expression corresponding to substring extraction
- Since:
- JPA 2.0
Extracts a substring starting at the specified position through to end of the string. First position is 1.
- Parameters:
x- string expressionfrom- start position
- Return:
- expression corresponding to substring extraction
- Since:
- JPA 2.0
Extracts a substring of given length starting at the specified position. First position is 1.
- Parameters:
x- string expressionfrom- start positionlen- length
- Return:
- expression corresponding to substring extraction
- Since:
- JPA 2.0
- Parameters:
x- expressiony- expression
- Return:
- sum
- Since:
- JPA 2.0
- Parameters:
x- expressiony- value
- Return:
- sum
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to sum operation
- Return:
- sum expression
- Since:
- JPA 2.0
- Parameters:
x- valuey- expression
- Return:
- sum
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to sum operation
- Return:
- sum expression
- Since:
- JPA 2.0
- Parameters:
x- expression representing input value to sum operation
- Return:
- sum expression
- Since:
- JPA 2.0
Returns same expression object.
- Parameters:
number- numeric expression
- Return:
- {@literal Expression
}
- Since:
- JPA 2.0
Returns same expression object.
- Parameters:
number- numeric expression
- Return:
- {@literal Expression
}
- Since:
- JPA 2.0
Returns same expression object.
- Parameters:
number- numeric expression
- Return:
- {@literal Expression
}
- Since:
- JPA 2.0
Returns same expression object.
- Parameters:
number- numeric expression
- Return:
- {@literal Expression
}
- Since:
- JPA 2.0
Returns same expression object.
- Parameters:
number- numeric expression
- Return:
- {@literal Expression
}
- Since:
- JPA 2.0
Returns same expression object.
- Parameters:
number- numeric expression
- Return:
- {@literal Expression
}
- Since:
- JPA 2.0
Returns same expression object.
- Parameters:
character- expression
- Return:
- {@literal Expression
}
- Since:
- JPA 2.0
- Parameters:
join- CollectionJoin objecttype- type to be downcast to
- Return:
- CollectionJoin object of the specified type
- Since:
- JPA 2.1
- Parameters:
join- Join objecttype- type to be downcast to
- Return:
- Join object of the specified type
- Since:
- JPA 2.1
- Parameters:
join- ListJoin objecttype- type to be downcast to
- Return:
- ListJoin object of the specified type
- Since:
- JPA 2.1
- Parameters:
join- MapJoin objecttype- type to be downcast to
- Return:
- MapJoin object of the specified type
- Since:
- JPA 2.1
- Parameters:
path- pathtype- type to be downcast to
- Return:
- Path object of the specified type
- Since:
- JPA 2.1
- Parameters:
root- roottype- type to be downcast to
- Return:
- Root object of the specified type
- Since:
- JPA 2.1
- Parameters:
join- SetJoin objecttype- type to be downcast to
- Return:
- SetJoin object of the specified type
- Since:
- JPA 2.1
- Parameters:
t- expression for character to be trimmedx- expression for string to trim
- Return:
- trim expression
- Since:
- JPA 2.0
- Parameters:
x- expression for string to trim
- Return:
- trim expression
- Since:
- JPA 2.0
- Parameters:
ts- trim specificationt- expression for character to be trimmedx- expression for string to trim
- Return:
- trim expression
- Since:
- JPA 2.0
- Parameters:
ts- trim specificationx- expression for string to trim
- Return:
- trim expression
- Since:
- JPA 2.0
- Parameters:
ts- trim specificationt- character to be trimmedx- expression for string to trim
- Return:
- trim expression
- Since:
- JPA 2.0
- Parameters:
t- character to be trimmedx- expression for string to trim
- Return:
- trim expression
- Since:
- JPA 2.0
- Parameters:
selections- list of selection items
- Return:
- tuple-valued compound selection
- Throws:
- IllegalArgumentException - if an argument is a tuple- or array-valued selection item
- Since:
- JPA 3.2
- Parameters:
selections- selection items
- Return:
- tuple-valued compound selection
- Throws:
- IllegalArgumentException - if an argument is a tuple- or array-valued selection item
- Since:
- JPA 2.0
- Return:
- a new criteria query which returns the union of the results of the given queries
- Since:
- JPA 3.2
- Return:
- a new criteria query which returns the union of the results of the given queries
- Since:
- JPA 3.2
- Parameters:
x- string expression
- Return:
- expression to convert to uppercase
- Since:
- JPA 2.0
- Parameters:
map- map
- Return:
- collection expression
- Since:
- JPA 2.0