JPA Interface

Subquery

Type Parameters:
<T> - the type of the selection item.
Super Interfaces:
AbstractQuery<T>, CommonAbstractCriteria, Expression<T>, Selection<T>, TupleElement<T>

The Subquery interface defines functionality that is specific to subqueries. A subquery has an expression as its selection item.
Since:
JPA 2.0

Public Methods

Expression<X> as(Class<X> type)
Perform a typecast upon the expression, returning a new expression object.
This method does not cause type conversion: the runtime type is not changed. Warning: may result in a runtime failure.
Parameters:
type - intended type of the expression
Return:
new expression of the given type
Inherited from:
Expression<T>
Since:
JPA 2.0
CollectionJoin<X,Y> correlate(CollectionJoin<X,Y> parentCollection)
Create a subquery collection join object correlated to a collection join object of the enclosing query.
Parameters:
parentCollection - join object of the containing query
Return:
subquery join
Since:
JPA 2.0
Join<X,Y> correlate(Join<X,Y> parentJoin)
Create a subquery join object correlated to a join object of the enclosing query.
Parameters:
parentJoin - join object of the containing query
Return:
subquery join
Since:
JPA 2.0
ListJoin<X,Y> correlate(ListJoin<X,Y> parentList)
Create a subquery list join object correlated to a list join object of the enclosing query.
Parameters:
parentList - join object of the containing query
Return:
subquery join
Since:
JPA 2.0
MapJoin<X,K,V> correlate(MapJoin<X,K,V> parentMap)
Create a subquery map join object correlated to a map join object of the enclosing query.
Parameters:
parentMap - join object of the containing query
Return:
subquery join
Since:
JPA 2.0
Root<Y> correlate(Root<Y> parentRoot)
Create a subquery root correlated to a root of the enclosing query.
Parameters:
parentRoot - a root of the containing query
Return:
subquery root
Since:
JPA 2.0
SetJoin<X,Y> correlate(SetJoin<X,Y> parentSet)
Create a subquery set join object correlated to a set join object of the enclosing query.
Parameters:
parentSet - join object of the containing query
Return:
subquery join
Since:
JPA 2.0
Subquery<T> distinct(boolean 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 value specifying whether duplicate results must be eliminated from the subquery result or whether they must be retained
Return:
the modified subquery.
Since:
JPA 2.0
Root<X> from(Class<X> entityClass)
Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.
Parameters:
entityClass - the entity class
Return:
query root corresponding to the given entity
Inherited from:
AbstractQuery<T>
Since:
JPA 2.0
Root<X> from(EntityType<X> entity)
Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.
Parameters:
entity - metamodel entity representing the entity of type X
Return:
query root corresponding to the given entity
Inherited from:
AbstractQuery<T>
Since:
JPA 2.0
Return the query of which this is a subquery.
This may be a CriteriaQuery, CriteriaUpdate, CriteriaDelete, or a Subquery.
Return:
the enclosing query or subquery
Since:
JPA 2.1
Return the correlated joins of the subquery.
Returns empty set if the subquery has no correlated joins. Modifications to the set do not affect the query.
Return:
the correlated joins of the subquery
Since:
JPA 2.0
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.
Return:
the list of grouping expressions
Inherited from:
AbstractQuery<T>
Since:
JPA 2.0
Return the predicate that corresponds to the restriction(s) over the grouping items, or null if no restrictions have been specified.
Return:
having clause predicate
Inherited from:
AbstractQuery<T>
Since:
JPA 2.0
AbstractQuery<?> getParent()
Return the query of which this is a subquery.
This must be a CriteriaQuery or a Subquery.
Return:
the enclosing query or subquery
Since:
JPA 2.0
Class<T> 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.
Return:
result type
Inherited from:
AbstractQuery<T>
Since:
JPA 2.0
Set<Root<?>> 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.
Return:
the set of query roots
Inherited from:
AbstractQuery<T>
Since:
JPA 2.0
Return the selection expression.
Return:
the item to be returned in the subquery result
Since:
JPA 2.0
Subquery<T> groupBy(Expression<?>... grouping)
Specify the expressions that are used to form groups over the subquery 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 - zero or more grouping expressions
Return:
the modified subquery
Since:
JPA 2.0
Subquery<T> groupBy(List<Expression<?>> grouping)
Specify the expressions that are used to form groups over the subquery 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 of zero or more grouping expressions
Return:
the modified subquery
Since:
JPA 2.0
Subquery<T> having(Expression<Boolean> restriction)
Specify a restriction over the groups of the subquery.
Replaces the previous having restriction(s), if any. This method only overrides the return type of the corresponding AbstractQuery method.
Parameters:
restriction - a simple or compound boolean expression
Return:
the modified subquery
Since:
JPA 2.0
Subquery<T> having(Predicate... restrictions)
Specify restrictions over the groups of the subquery 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 - zero or more restriction predicates
Return:
the modified subquery
Since:
JPA 2.0
Predicate in(Collection<?> values)
Create a predicate to test whether the expression is a member of the collection.
Parameters:
values - collection of values to be tested against
Return:
predicate testing for membership
Inherited from:
Expression<T>
Since:
JPA 2.0
Predicate in(Expression<?>... values)
Create a predicate to test whether the expression is a member of the argument list.
Parameters:
values - expressions to be tested against
Return:
predicate testing for membership
Inherited from:
Expression<T>
Since:
JPA 2.0
Predicate in(Expression<Collection<?>> values)
Create a predicate to test whether the expression is a member of the collection.
Parameters:
values - expression corresponding to collection to be tested against
Return:
predicate testing for membership
Inherited from:
Expression<T>
Since:
JPA 2.0
Predicate in(Object... values)
Create a predicate to test whether the expression is a member of the argument list.
Parameters:
values - values to be tested against
Return:
predicate testing for membership
Inherited from:
Expression<T>
Since:
JPA 2.0
boolean isDistinct()
Return whether duplicate query results must be eliminated or retained.
Return:
boolean indicating whether duplicate query results must be eliminated
Inherited from:
AbstractQuery<T>
Since:
JPA 2.0
Create a predicate to test whether the expression is not null.
Return:
predicate testing whether the expression is not null
Inherited from:
Expression<T>
Since:
JPA 2.0
Create a predicate to test whether the expression is null.
Return:
predicate testing whether the expression is null
Inherited from:
Expression<T>
Since:
JPA 2.0
Subquery<T> select(Expression<T> expression)
Specify the item that is to be returned as the subquery result.
Replaces the previously specified selection, if any.
Parameters:
expression - expression specifying the item that is to be returned as the subquery result
Return:
the modified subquery
Since:
JPA 2.0
Subquery<T> where(Expression<Boolean> restriction)
Modify the subquery to restrict the 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 - a simple or compound boolean expression
Return:
the modified subquery
Since:
JPA 2.0
Subquery<T> where(Predicate... restrictions)
Modify the subquery to restrict the 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 - zero or more restriction predicates
Return:
the modified subquery
Since:
JPA 2.0