Top Description Methods
org.hibernate.query.criteria

public Interface JpaCriteriaQuery<T>

extends CriteriaQuery<T>, JpaQueryableCriteria<T>, JpaSelectCriteria<T>
Known Direct Implementers
org.hibernate.query.sqm.tree.select.SqmSelectStatement, org.hibernate.query.criteria.CriteriaDefinition
Imports
java.util.List, .Set, jakarta.persistence.criteria.CriteriaQuery, .Expression, .Order, .ParameterExpression, .Predicate, .Root, .Selection, jakarta.persistence.metamodel.EntityType, org.hibernate.query.sqm.FetchClauseType

Extension of the JPA CriteriaQuery
Author
Steve Ebersole

Method Summary

Modifier and TypeMethod and Description
public JpaCriteriaQuery<Long>
createCountQuery()

Wraps this query in a subquery and returns a count query based on that subquery in the from clause.

public JpaCriteriaQuery<T>
distinct(boolean
boolean value specifying whether duplicate results must be eliminated from the query result or whether they must be retained
distinct
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.distinct, org.hibernate.query.criteria.JpaSelectCriteria.distinct.

Specify whether duplicate query results will be eliminated.
public JpaCriteriaQuery<T>
fetch(JpaExpression<? extends Number> fetch)

public JpaCriteriaQuery<T>
fetch(JpaExpression<? extends Number> fetch, FetchClauseType fetchClauseType)

public JpaCriteriaQuery<T>
fetch(Number fetch)

public JpaCriteriaQuery<T>
fetch(Number fetch, FetchClauseType fetchClauseType)

public <X> JpaRoot<X>
from(Class<X>
the entity class
entityClass
)

Redeclares jakarta.persistence.criteria.AbstractQuery.from, org.hibernate.query.criteria.JpaSelectCriteria.from.

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.
public <X> JpaRoot<X>
from(EntityType<X>
metamodel entity representing the entity of type X
entity
)

Redeclares jakarta.persistence.criteria.AbstractQuery.from, org.hibernate.query.criteria.JpaSelectCriteria.from.

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.
public JpaExpression<Number>
public FetchClauseType
public JpaExpression<Number>
public default List<Order>
getOrderList()

Implements jakarta.persistence.criteria.CriteriaQuery.getOrderList.

Return the ordering expressions in order of precedence.
public Set<ParameterExpression<?>>
getParameters()

Redeclares jakarta.persistence.criteria.CriteriaQuery.getParameters.

Return the parameters of the query.
public List<Root<?>>
getRootList()

Return the roots as a list.

public JpaCriteriaQuery<T>
groupBy(Expression<?>...
zero or more grouping expressions
grouping
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.groupBy, org.hibernate.query.criteria.JpaSelectCriteria.groupBy.

Specify the expressions that are used to form groups over the query results.
public JpaCriteriaQuery<T>
groupBy(List<Expression<?>>
list of zero or more grouping expressions
grouping
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.groupBy, org.hibernate.query.criteria.JpaSelectCriteria.groupBy.

Specify the expressions that are used to form groups over the query results.
public JpaCriteriaQuery<T>
having(Expression<Boolean>
a simple or compound boolean expression
restriction
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.having, org.hibernate.query.criteria.JpaSelectCriteria.having.

Specify a restriction over the groups of the query.
public JpaCriteriaQuery<T>
having(Predicate...
zero or more restriction predicates
restrictions
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.having, org.hibernate.query.criteria.JpaSelectCriteria.having.

Specify restrictions over the groups of the query according the conjunction of the specified restriction predicates.
public JpaCriteriaQuery<T>
multiselect(Selection<?>...
selection items corresponding to the results to be returned by the query
selections
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.multiselect.

Specify the selection items that are to be returned in the query result.
public JpaCriteriaQuery<T>
multiselect(List<Selection<?>>
list of selection items corresponding to the results to be returned by the query
selectionList
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.multiselect.

Specify the selection items that are to be returned in the query result.
public JpaCriteriaQuery<T>
offset(JpaExpression<? extends Number> offset)

public JpaCriteriaQuery<T>
offset(Number offset)

public JpaCriteriaQuery<T>
orderBy(Order...
zero or more ordering expressions
o
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.orderBy.

Specify the ordering expressions that are used to order the query results.
public JpaCriteriaQuery<T>
orderBy(List<Order>
list of zero or more ordering expressions
o
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.orderBy.

Specify the ordering expressions that are used to order the query results.
public JpaCriteriaQuery<T>
select(Selection<? extends T>
selection specifying the item that is to be returned in the query result
selection
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.select.

Specify the item that is to be returned in the query result.
public JpaCriteriaQuery<T>
where(Expression<Boolean>
a simple or compound boolean expression
restriction
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.where, org.hibernate.query.criteria.JpaSelectCriteria.where.

Modify the query to restrict the query result according to the specified boolean expression.
public JpaCriteriaQuery<T>
where(Predicate...
zero or more restriction predicates
restrictions
)

Redeclares jakarta.persistence.criteria.CriteriaQuery.where, org.hibernate.query.criteria.JpaSelectCriteria.where.

Modify the query to restrict the query result according to the conjunction of the specified restriction predicates.
Inherited from org.hibernate.query.criteria.JpaSelectCriteria:
fromfromgetGroupRestrictiongetQueryPartgetQuerySpecgetRestrictiongetSelection

Method Detail

createCountQueryback to summary
public JpaCriteriaQuery<Long> createCountQuery()

Wraps this query in a subquery and returns a count query based on that subquery in the from clause.

Since
6.4
distinctback to summary
public JpaCriteriaQuery<T> distinct(boolean distinct)

Redeclares jakarta.persistence.criteria.CriteriaQuery.distinct, org.hibernate.query.criteria.JpaSelectCriteria.distinct.

Doc from jakarta.persistence.criteria.CriteriaQuery.distinct.

Specify whether duplicate query results will be eliminated. A true value will cause duplicates to be eliminated. A false value will cause duplicates to be retained. If distinct has not been specified, duplicate results must be retained. This method only overrides the return type of the corresponding AbstractQuery method.

Parameters
distinct:boolean

boolean value specifying whether duplicate results must be eliminated from the query result or whether they must be retained

Returns:JpaCriteriaQuery<T>

the modified query.

Annotations
@Override
fetchback to summary
public JpaCriteriaQuery<T> fetch(JpaExpression<? extends Number> fetch)
fetchback to summary
public JpaCriteriaQuery<T> fetch(JpaExpression<? extends Number> fetch, FetchClauseType fetchClauseType)
fetchback to summary
public JpaCriteriaQuery<T> fetch(Number fetch)
fetchback to summary
public JpaCriteriaQuery<T> fetch(Number fetch, FetchClauseType fetchClauseType)
fromback to summary
public <X> JpaRoot<X> from(Class<X> entityClass)

Redeclares jakarta.persistence.criteria.AbstractQuery.from, org.hibernate.query.criteria.JpaSelectCriteria.from.

Doc from jakarta.persistence.criteria.AbstractQuery.from.

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.

Parameters
entityClass:Class<X>

the entity class

Returns:JpaRoot<X>

query root corresponding to the given entity

Annotations
@Override
fromback to summary
public <X> JpaRoot<X> from(EntityType<X> entity)

Redeclares jakarta.persistence.criteria.AbstractQuery.from, org.hibernate.query.criteria.JpaSelectCriteria.from.

Doc from jakarta.persistence.criteria.AbstractQuery.from.

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.

Parameters
entity:EntityType<X>

metamodel entity representing the entity of type X

Returns:JpaRoot<X>

query root corresponding to the given entity

Annotations
@Override
getFetchback to summary
public JpaExpression<Number> getFetch()
getFetchClauseTypeback to summary
public FetchClauseType getFetchClauseType()
getOffsetback to summary
public JpaExpression<Number> getOffset()
getOrderListback to summary
public default List<Order> getOrderList()

Implements jakarta.persistence.criteria.CriteriaQuery.getOrderList.

Doc from jakarta.persistence.criteria.CriteriaQuery.getOrderList.

Return the ordering expressions in order of precedence. Returns empty list if no ordering expressions have been specified. Modifications to the list do not affect the query.

Returns:List<Order>

the list of ordering expressions

Annotations
@Override
@SuppressWarnings:unchecked
getParametersback to summary
public Set<ParameterExpression<?>> getParameters()

Redeclares jakarta.persistence.criteria.CriteriaQuery.getParameters.

Doc from jakarta.persistence.criteria.CriteriaQuery.getParameters.

Return the parameters of the query. Returns empty set if there are no parameters. Modifications to the set do not affect the query.

API Note

Warning! This actually walks the criteria tree looking for parameters nodes.

Returns:Set<ParameterExpression<?>>

the query parameters

Annotations
@Override
getRootListback to summary
public List<Root<?>> getRootList()

Return the roots as a list.

groupByback to summary
public JpaCriteriaQuery<T> groupBy(Expression<?>... grouping)

Redeclares jakarta.persistence.criteria.CriteriaQuery.groupBy, org.hibernate.query.criteria.JpaSelectCriteria.groupBy.

Doc from jakarta.persistence.criteria.CriteriaQuery.groupBy.

Specify the expressions that are used to form groups over the query results. Replaces the previous specified grouping expressions, if any. If no grouping expressions are specified, any previously added grouping expressions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.

Parameters
grouping:Expression<?>[]

zero or more grouping expressions

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
groupByback to summary
public JpaCriteriaQuery<T> groupBy(List<Expression<?>> grouping)

Redeclares jakarta.persistence.criteria.CriteriaQuery.groupBy, org.hibernate.query.criteria.JpaSelectCriteria.groupBy.

Doc from jakarta.persistence.criteria.CriteriaQuery.groupBy.

Specify the expressions that are used to form groups over the query results. Replaces the previous specified grouping expressions, if any. If no grouping expressions are specified, any previously added grouping expressions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.

Parameters
grouping:List<Expression<?>>

list of zero or more grouping expressions

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
havingback to summary
public JpaCriteriaQuery<T> having(Expression<Boolean> restriction)

Redeclares jakarta.persistence.criteria.CriteriaQuery.having, org.hibernate.query.criteria.JpaSelectCriteria.having.

Doc from jakarta.persistence.criteria.CriteriaQuery.having.

Specify a restriction over the groups of the query. Replaces the previous having restriction(s), if any. This method only overrides the return type of the corresponding AbstractQuery method.

Parameters
restriction:Expression<Boolean>

a simple or compound boolean expression

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
havingback to summary
public JpaCriteriaQuery<T> having(Predicate... restrictions)

Redeclares jakarta.persistence.criteria.CriteriaQuery.having, org.hibernate.query.criteria.JpaSelectCriteria.having.

Doc from jakarta.persistence.criteria.CriteriaQuery.having.

Specify restrictions over the groups of the query according the conjunction of the specified restriction predicates. Replaces the previously added having restriction(s), if any. If no restrictions are specified, any previously added restrictions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.

Parameters
restrictions:Predicate[]

zero or more restriction predicates

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
multiselectback to summary
public JpaCriteriaQuery<T> multiselect(Selection<?>... selections)

Redeclares jakarta.persistence.criteria.CriteriaQuery.multiselect.

Doc from jakarta.persistence.criteria.CriteriaQuery.multiselect.

Specify the selection items that are to be returned in the query result. Replaces the previously specified selection(s), if any. The type of the result of the query execution depends on the specification of the type of the criteria query object created as well as the arguments to the multiselect method.

An argument to the multiselect method must not be a tuple- or array-valued compound selection item.

The semantics of this method are as follows:

  • If the type of the criteria query is CriteriaQuery<Tuple> (i.e., a criteria query object created by either the createTupleQuery method or by passing a Tuple class argument to the createQuery method), a Tuple object corresponding to the arguments of the multiselect method, in the specified order, will be instantiated and returned for each row that results from the query execution.
  • If the type of the criteria query is CriteriaQuery<X> for some user-defined class X (i.e., a criteria query object created by passing a X class argument to the createQuery method), the arguments to the multiselect method will be passed to the X constructor and an instance of type X will be returned for each row.
  • If the type of the criteria query is CriteriaQuery<X[]> for some class X, an instance of type X[] will be returned for each row. The elements of the array will correspond to the arguments of the multiselect method, in the specified order.
  • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and only a single argument is passed to the multiselect method, an instance of type Object will be returned for each row.
  • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and more than one argument is passed to the multiselect method, an instance of type Object[] will be instantiated and returned for each row. The elements of the array will correspond to the arguments to the multiselect method, in the specified order.
Parameters
selections:Selection<?>[]

selection items corresponding to the results to be returned by the query

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
multiselectback to summary
public JpaCriteriaQuery<T> multiselect(List<Selection<?>> selectionList)

Redeclares jakarta.persistence.criteria.CriteriaQuery.multiselect.

Doc from jakarta.persistence.criteria.CriteriaQuery.multiselect.

Specify the selection items that are to be returned in the query result. Replaces the previously specified selection(s), if any.

The type of the result of the query execution depends on the specification of the type of the criteria query object created as well as the argument to the multiselect method. An element of the list passed to the multiselect method must not be a tuple- or array-valued compound selection item.

The semantics of this method are as follows:

  • If the type of the criteria query is CriteriaQuery<Tuple> (i.e., a criteria query object created by either the createTupleQuery method or by passing a Tuple class argument to the createQuery method), a Tuple object corresponding to the elements of the list passed to the multiselect method, in the specified order, will be instantiated and returned for each row that results from the query execution.
  • If the type of the criteria query is CriteriaQuery<X> for some user-defined class X (i.e., a criteria query object created by passing a X class argument to the createQuery method), the elements of the list passed to the multiselect method will be passed to the X constructor and an instance of type X will be returned for each row.
  • If the type of the criteria query is CriteriaQuery<X[]> for some class X, an instance of type X[] will be returned for each row. The elements of the array will correspond to the elements of the list passed to the multiselect method, in the specified order.
  • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and the list passed to the multiselect method contains only a single element, an instance of type Object will be returned for each row.
  • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and the list passed to the multiselect method contains more than one element, an instance of type Object[] will be instantiated and returned for each row. The elements of the array will correspond to the elements of the list passed to the multiselect method, in the specified order.
Parameters
selectionList:List<Selection<?>>

list of selection items corresponding to the results to be returned by the query

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
offsetback to summary
public JpaCriteriaQuery<T> offset(JpaExpression<? extends Number> offset)
offsetback to summary
public JpaCriteriaQuery<T> offset(Number offset)
orderByback to summary
public JpaCriteriaQuery<T> orderBy(Order... o)

Redeclares jakarta.persistence.criteria.CriteriaQuery.orderBy.

Doc from jakarta.persistence.criteria.CriteriaQuery.orderBy.

Specify the ordering expressions that are used to order the query results. Replaces the previous ordering expressions, if any. If no ordering expressions are specified, the previous ordering, if any, is simply removed, and results will be returned in no particular order. The left-to-right sequence of the ordering expressions determines the precedence, whereby the leftmost has highest precedence.

Parameters
o:Order[]

zero or more ordering expressions

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
orderByback to summary
public JpaCriteriaQuery<T> orderBy(List<Order> o)

Redeclares jakarta.persistence.criteria.CriteriaQuery.orderBy.

Doc from jakarta.persistence.criteria.CriteriaQuery.orderBy.

Specify the ordering expressions that are used to order the query results. Replaces the previous ordering expressions, if any. If no ordering expressions are specified, the previous ordering, if any, is simply removed, and results will be returned in no particular order. The order of the ordering expressions in the list determines the precedence, whereby the first element in the list has highest precedence.

Parameters
o:List<Order>

list of zero or more ordering expressions

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
selectback to summary
public JpaCriteriaQuery<T> select(Selection<? extends T> selection)

Redeclares jakarta.persistence.criteria.CriteriaQuery.select.

Doc from jakarta.persistence.criteria.CriteriaQuery.select.

Specify the item that is to be returned in the query result. Replaces the previously specified selection(s), if any.

Note

Applications using the string-based API may need to specify the type of the select item when it results from a get or join operation and the query result type is specified.

    For example:

    CriteriaQuery<String> q = cb.createQuery(String.class);
    Root<Order> order = q.from(Order.class);
    q.select(order.get("shippingAddress").<String>get("state"));

    CriteriaQuery<Product> q2 = cb.createQuery(Product.class);
    q2.select(q2.from(Order.class)
                .join("items")
                .<Item,Product>join("product"));

Parameters
selection:Selection<? extends T>

selection specifying the item that is to be returned in the query result

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
whereback to summary
public JpaCriteriaQuery<T> where(Expression<Boolean> restriction)

Redeclares jakarta.persistence.criteria.CriteriaQuery.where, org.hibernate.query.criteria.JpaSelectCriteria.where.

Doc from jakarta.persistence.criteria.CriteriaQuery.where.

Modify the query to restrict the query result according to the specified boolean expression. Replaces the previously added restriction(s), if any. This method only overrides the return type of the corresponding AbstractQuery method.

Parameters
restriction:Expression<Boolean>

a simple or compound boolean expression

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override
whereback to summary
public JpaCriteriaQuery<T> where(Predicate... restrictions)

Redeclares jakarta.persistence.criteria.CriteriaQuery.where, org.hibernate.query.criteria.JpaSelectCriteria.where.

Doc from jakarta.persistence.criteria.CriteriaQuery.where.

Modify the query to restrict the query result according to the conjunction of the specified restriction predicates. Replaces the previously added restriction(s), if any. If no restrictions are specified, any previously added restrictions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.

Parameters
restrictions:Predicate[]

zero or more restriction predicates

Returns:JpaCriteriaQuery<T>

the modified query

Annotations
@Override