Criteria Query Selection and Results
The JPA Criteria API interfaces in this group are in use for setting the SELECT and ORDER BY clauses and for representing query results as tuples.
SELECT Clause Elements
The content of the SELECT clause in a criteria query is represented by
Selection is a super interface of
Expression, any criteria expression can be used as the SELECT clause content. Multiple selection expressions can be represented by
CompoundSelection, which is itself a subinterface of
See the SELECT in Criteria Queries section for more details and examples.
ORDER BY Clause Elements
Elements in the ORDER BY clause are represented by the
The Order interface is a thin wrapper around
Expressionjavax.persistence.criteria.ExpressionJPA interfaceType for query expressions.See JavaDoc Reference Page..., which adds order direction - either ascending (ASC) or descending (DESC). The
CriteriaBuilderjavax.persistence.criteria.CriteriaBuilderJPA interfaceUsed to construct criteria queries, compound selections, expressions, predicates, orderings.See JavaDoc Reference Page...'s
ascasc(x)CriteriaBuilder's methodCreate an ordering by the ascending value of the expression.See JavaDoc Reference Page... and
descdesc(x)CriteriaBuilder's methodCreate an ordering by the descending value of the expression.See JavaDoc Reference Page... methods take an expression and return an ascending or descending
Order instance (respectively).
See the ORDER BY in Criteria Queries section for more details and examples.
Query Results as Tuples
JPA 2 introduces a new way to represent multi selection results (i.e. results of a query with multiple expressions in the SELECT clause) using tuples:
Tuplejavax.persistence.TupleJPA interfaceInterface for extracting the elements of a query result tuple.See JavaDoc Reference Page... interface can be used as a clean alternative to
Object. See the SELECT in Criteria Queries for more details and examples.
These interfaces are defined outside the
javax.persistence.criteria package, since they might be useful also in string based JPQL queries. Using tuples with non criteria queries is supported by ObjectDB and it may be supported in the future by all the JPA providers.