ObjectDB ObjectDB

Criteria Query Selection and Results

The JPA Criteria API interfaces in this group are used 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:

Because 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 Selection:

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 Order interface:

The Order interface is a thin wrapper around Expression, which adds order direction - either ascending (ASC) or descending (DESC). The CriteriaBuilder's asc and desc 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:

The Tuple 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.