Top Description Fields Constructors Methods
org.hibernate.query.criteria.internal

public Class CriteriaQueryImpl<T>

extends AbstractNode
implements CriteriaQuery<T>, CompilableCriteria, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.hibernate.query.criteria.internal.compile.CompilableCriteria, javax.persistence.criteria.CriteriaQuery, javax.persistence.criteria.AbstractQuery, javax.persistence.criteria.CommonAbstractCriteria
Imports
java.io.Serializable, java.util.Arrays, .Collections, .HashMap, .List, .Map, .Set, javax.persistence.Tuple, javax.persistence.criteria.CriteriaQuery, .Expression, .Order, .ParameterExpression, .Predicate, .Root, .Selection, .Subquery, javax.persistence.metamodel.EntityType, org.hibernate.engine.spi.SharedSessionContractImplementor, org.hibernate.jpa.spi.HibernateEntityManagerImplementor, org.hibernate.query.criteria.internal.compile.CompilableCriteria, .CriteriaInterpretation, .CriteriaQueryTypeQueryAdapter, .ImplicitParameterBinding, .InterpretedParameterMetadata, .RenderingContext, org.hibernate.query.spi.QueryImplementor, org.hibernate.sql.ast.Clause, org.hibernate.type.Type, org.jboss.logging.Logger

The Hibernate implementation of the JPA CriteriaQuery contract. Mostly a set of delegation to its internal QueryStructure.
Author
Steve Ebersole

Field Summary

Modifier and TypeField and Description
private static final Logger
private List<Order>
private final QueryStructure<T>
private final Class<T>

Constructor Summary

AccessConstructor and Description
public
CriteriaQueryImpl(CriteriaBuilderImpl criteriaBuilder, Class<T> returnType)

Method Summary

Modifier and TypeMethod and Description
public void
applySelection(Selection<? extends T> selection)

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

Implements javax.persistence.criteria.CriteriaQuery.distinct.

Specify whether duplicate query results will be eliminated.
public <X> Root<X>
from(EntityType<X>
metamodel entity representing the entity of type X
entityType
)

Implements javax.persistence.criteria.AbstractQuery.from.

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.
public <X> Root<X>
from(Class<X>
the entity class
entityClass
)

Implements javax.persistence.criteria.AbstractQuery.from.

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.
public List<Expression<?>>
getGroupList()

Implements javax.persistence.criteria.AbstractQuery.getGroupList.

Return a list of the grouping expressions.
public Predicate
getGroupRestriction()

Implements javax.persistence.criteria.AbstractQuery.getGroupRestriction.

Return the predicate that corresponds to the restriction(s) over the grouping items, or null if no restrictions have been specified.
public List<Order>
getOrderList()

Implements javax.persistence.criteria.CriteriaQuery.getOrderList.

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

Implements javax.persistence.criteria.CriteriaQuery.getParameters.

Return the parameters of the query.
protected QueryStructure<T>
public Predicate
getRestriction()

Implements javax.persistence.criteria.CommonAbstractCriteria.getRestriction.

Return the predicate that corresponds to the where clause restriction(s), or null if no restrictions have been specified.
public Class<T>
getResultType()

Implements javax.persistence.criteria.AbstractQuery.getResultType.

Return the result type of the query or subquery.
public Set<Root<?>>
getRoots()

Implements javax.persistence.criteria.AbstractQuery.getRoots.

Return the query roots.
public Selection<T>
getSelection()

Implements javax.persistence.criteria.AbstractQuery.getSelection.

Return the selection of the query, or null if no selection has been set.
public CriteriaQuery<T>
groupBy(Expression<?>...
zero or more grouping expressions
groupings
)

Implements javax.persistence.criteria.CriteriaQuery.groupBy.

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

Implements javax.persistence.criteria.CriteriaQuery.groupBy.

Specify the expressions that are used to form groups over the query results.
private boolean

Returns:

True if there is an explicit selection; false otherwise.
hasImplicitSelection
()

If no explicit selection was defined, we have a condition called an implicit selection if the query specified a single Root and the java type of that root's model is the same as this criteria's result type.

public CriteriaQuery<T>
having(Expression<Boolean>
a simple or compound boolean expression
expression
)

Implements javax.persistence.criteria.CriteriaQuery.having.

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

Implements javax.persistence.criteria.CriteriaQuery.having.

Specify restrictions over the groups of the query according the conjunction of the specified restriction predicates.
public CriteriaInterpretation
public boolean
isDistinct()

Implements javax.persistence.criteria.AbstractQuery.isDistinct.

Return whether duplicate query results must be eliminated or retained.
public CriteriaQuery<T>
multiselect(Selection<?>...
selection items corresponding to the results to be returned by the query
selections
)

Implements javax.persistence.criteria.CriteriaQuery.multiselect.

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

Implements javax.persistence.criteria.CriteriaQuery.multiselect.

Specify the selection items that are to be returned in the query result.
public CriteriaQuery<T>
orderBy(Order...
zero or more ordering expressions
orders
)

Implements javax.persistence.criteria.CriteriaQuery.orderBy.

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

Implements javax.persistence.criteria.CriteriaQuery.orderBy.

Specify the ordering expressions that are used to order the query results.
protected void
renderOrderByClause(RenderingContext renderingContext, StringBuilder jpaqlBuffer)

public CriteriaQuery<T>
select(Selection<? extends T>
selection specifying the item that is to be returned in the query result
selection
)

Implements javax.persistence.criteria.CriteriaQuery.select.

Specify the item that is to be returned in the query result.
public <U> Subquery<U>
subquery(Class<U>
the subquery result type
subqueryType
)

Implements javax.persistence.criteria.CommonAbstractCriteria.subquery.

Create a subquery of the query.
public void
public CriteriaQuery<T>
where(Expression<Boolean>
a simple or compound boolean expression
expression
)

Implements javax.persistence.criteria.CriteriaQuery.where.

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

Implements javax.persistence.criteria.CriteriaQuery.where.

Modify the query to restrict the query result according to the conjunction of the specified restriction predicates.
Inherited from org.hibernate.query.criteria.internal.AbstractNode:
criteriaBuilder

Field Detail

logback to summary
private static final Logger log
orderSpecsback to summary
private List<Order> orderSpecs
queryStructureback to summary
private final QueryStructure<T> queryStructure
returnTypeback to summary
private final Class<T> returnType

Constructor Detail

CriteriaQueryImplback to summary
public CriteriaQueryImpl(CriteriaBuilderImpl criteriaBuilder, Class<T> returnType)

Method Detail

applySelectionback to summary
public void applySelection(Selection<? extends T> selection)
distinctback to summary
public CriteriaQuery<T> distinct(boolean applyDistinction)

Implements javax.persistence.criteria.CriteriaQuery.distinct.

Doc from javax.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
applyDistinction:boolean

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

Returns:CriteriaQuery<T>

the modified query.

Annotations
@Override
fromback to summary
public <X> Root<X> from(EntityType<X> entityType)

Implements javax.persistence.criteria.AbstractQuery.from.

Doc from javax.persistence.criteria.AbstractQuery.from.

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

Parameters
entityType:EntityType<X>

metamodel entity representing the entity of type X

Returns:Root<X>

query root corresponding to the given entity

Annotations
@Override
fromback to summary
public <X> Root<X> from(Class<X> entityClass)

Implements javax.persistence.criteria.AbstractQuery.from.

Doc from javax.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:Root<X>

query root corresponding to the given entity

Annotations
@Override
getGroupListback to summary
public List<Expression<?>> getGroupList()

Implements javax.persistence.criteria.AbstractQuery.getGroupList.

Doc from javax.persistence.criteria.AbstractQuery.getGroupList.

Return a list of the grouping expressions. Returns empty list if no grouping expressions have been specified. Modifications to the list do not affect the query.

Returns:List<Expression<?>>

the list of grouping expressions

Annotations
@Override
getGroupRestrictionback to summary
public Predicate getGroupRestriction()

Implements javax.persistence.criteria.AbstractQuery.getGroupRestriction.

Doc from javax.persistence.criteria.AbstractQuery.getGroupRestriction.

Return the predicate that corresponds to the restriction(s) over the grouping items, or null if no restrictions have been specified.

Returns:Predicate

having clause predicate

Annotations
@Override
getOrderListback to summary
public List<Order> getOrderList()

Implements javax.persistence.criteria.CriteriaQuery.getOrderList.

Doc from javax.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
getParametersback to summary
public Set<ParameterExpression<?>> getParameters()

Implements javax.persistence.criteria.CriteriaQuery.getParameters.

Doc from javax.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.

Returns:Set<ParameterExpression<?>>

the query parameters

Annotations
@Override
getQueryStructureback to summary
protected QueryStructure<T> getQueryStructure()
getRestrictionback to summary
public Predicate getRestriction()

Implements javax.persistence.criteria.CommonAbstractCriteria.getRestriction.

Doc from javax.persistence.criteria.CommonAbstractCriteria.getRestriction.

Return the predicate that corresponds to the where clause restriction(s), or null if no restrictions have been specified.

Returns:Predicate

where clause predicate

Annotations
@Override
getResultTypeback to summary
public Class<T> getResultType()

Implements javax.persistence.criteria.AbstractQuery.getResultType.

Doc from javax.persistence.criteria.AbstractQuery.getResultType.

Return the result type of the query or subquery. If a result type was specified as an argument to the createQuery or subquery method, that type will be returned. If the query was created using the createTupleQuery method, the result type is Tuple. Otherwise, the result type is Object.

Returns:Class<T>

result type

Annotations
@Override
getRootsback to summary
public Set<Root<?>> getRoots()

Implements javax.persistence.criteria.AbstractQuery.getRoots.

Doc from javax.persistence.criteria.AbstractQuery.getRoots.

Return the query roots. These are the roots that have been defined for the CriteriaQuery or Subquery itself, including any subquery roots defined as a result of correlation. Returns empty set if no roots have been defined. Modifications to the set do not affect the query.

Returns:Set<Root<?>>

the set of query roots

Annotations
@Override
getSelectionback to summary
public Selection<T> getSelection()

Implements javax.persistence.criteria.AbstractQuery.getSelection.

Doc from javax.persistence.criteria.AbstractQuery.getSelection.

Return the selection of the query, or null if no selection has been set.

Returns:Selection<T>

selection item

Annotations
@Override
@SuppressWarnings:unchecked
groupByback to summary
public CriteriaQuery<T> groupBy(Expression<?>... groupings)

Implements javax.persistence.criteria.CriteriaQuery.groupBy.

Doc from javax.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
groupings:Expression<?>[]

zero or more grouping expressions

Returns:CriteriaQuery<T>

the modified query

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

Implements javax.persistence.criteria.CriteriaQuery.groupBy.

Doc from javax.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
groupings:List<Expression<?>>

list of zero or more grouping expressions

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override
hasImplicitSelectionback to summary
private boolean hasImplicitSelection()

If no explicit selection was defined, we have a condition called an implicit selection if the query specified a single Root and the java type of that root's model is the same as this criteria's result type.

Returns:boolean

True if there is an explicit selection; false otherwise.

havingback to summary
public CriteriaQuery<T> having(Expression<Boolean> expression)

Implements javax.persistence.criteria.CriteriaQuery.having.

Doc from javax.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
expression:Expression<Boolean>

a simple or compound boolean expression

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override
havingback to summary
public CriteriaQuery<T> having(Predicate... predicates)

Implements javax.persistence.criteria.CriteriaQuery.having.

Doc from javax.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
predicates:Predicate[]

zero or more restriction predicates

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override
interpretback to summary
public CriteriaInterpretation interpret(RenderingContext renderingContext)

Implements org.hibernate.query.criteria.internal.compile.CompilableCriteria.interpret.

Annotations
@Override
isDistinctback to summary
public boolean isDistinct()

Implements javax.persistence.criteria.AbstractQuery.isDistinct.

Doc from javax.persistence.criteria.AbstractQuery.isDistinct.

Return whether duplicate query results must be eliminated or retained.

Returns:boolean

boolean indicating whether duplicate query results must be eliminated

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

Implements javax.persistence.criteria.CriteriaQuery.multiselect.

Doc from javax.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:CriteriaQuery<T>

the modified query

Annotations
@Override
@SuppressWarnings:unchecked
multiselectback to summary
public CriteriaQuery<T> multiselect(List<Selection<?>> selections)

Implements javax.persistence.criteria.CriteriaQuery.multiselect.

Doc from javax.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
selections:List<Selection<?>>

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

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override
@SuppressWarnings:unchecked
orderByback to summary
public CriteriaQuery<T> orderBy(Order... orders)

Implements javax.persistence.criteria.CriteriaQuery.orderBy.

Doc from javax.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
orders:Order[]

zero or more ordering expressions

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override
orderByback to summary
public CriteriaQuery<T> orderBy(List<Order> orders)

Implements javax.persistence.criteria.CriteriaQuery.orderBy.

Doc from javax.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
orders:List<Order>

list of zero or more ordering expressions

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override
renderOrderByClauseback to summary
protected void renderOrderByClause(RenderingContext renderingContext, StringBuilder jpaqlBuffer)
selectback to summary
public CriteriaQuery<T> select(Selection<? extends T> selection)

Implements javax.persistence.criteria.CriteriaQuery.select.

Doc from javax.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:CriteriaQuery<T>

the modified query

Annotations
@Override
subqueryback to summary
public <U> Subquery<U> subquery(Class<U> subqueryType)

Implements javax.persistence.criteria.CommonAbstractCriteria.subquery.

Doc from javax.persistence.criteria.CommonAbstractCriteria.subquery.

Create a subquery of the query.

Parameters
subqueryType:Class<U>

the subquery result type

Returns:Subquery<U>

subquery

Annotations
@Override
validateback to summary
public void validate()

Implements org.hibernate.query.criteria.internal.compile.CompilableCriteria.validate.

Annotations
@Override
whereback to summary
public CriteriaQuery<T> where(Expression<Boolean> expression)

Implements javax.persistence.criteria.CriteriaQuery.where.

Doc from javax.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
expression:Expression<Boolean>

a simple or compound boolean expression

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override
whereback to summary
public CriteriaQuery<T> where(Predicate... predicates)

Implements javax.persistence.criteria.CriteriaQuery.where.

Doc from javax.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
predicates:Predicate[]

zero or more restriction predicates

Returns:CriteriaQuery<T>

the modified query

Annotations
@Override