Package jakarta.persistence.criteria


package jakarta.persistence.criteria
Defines the Jakarta Persistence Criteria Query API. Criteria queries allow programmatic construction or manipulation of Jakarta Persistence queries.
  • CriteriaBuilder is the entry point for constructing queries, expressions, predicates, projections, and ordering criteria.
  • CriteriaQuery represents a top-level query slection query.
  • CriteriaUpdate and CriteriaDelete represents update and delete statements, respectively.
  • Expression and its subtypes represent expressions of various types.
  • Selection represents a projected value in a query result list.
  • Order represents an ordering criterion.

This example demonstrates the use of the Criteria API:

var builder = factory.getCriteriaBuilder();
var query = builder.createQuery(Book.class);
// specify the root entity of the query
var book = query.from(Book.class);
// fetch an association belonging to the root entity
book.fetch(Book_.authors, JoinType.LEFT);
if (titlePattern != null) {
    // add a restriction to the query
    query.where(book.get(Book_.title).like("%Persistence%"));
}
var books = agent.createQuery(query).getResultList();

The example demonstrates the use of the static metamodel type Book_ corresponding to the entity type Book to obtain references to persistent members of Book. Use of the static metamodel is usually preferred to passing string-valued attribute names during query construction.

Since:
2.0
  • Class
    Description
    The AbstractQuery interface defines functionality that is common to both top-level queries and subqueries.
    Type for boolean query expressions.
    Represents a simple or compound attribute path from a bound type or collection, and is a "primitive" expression of a boolean type.
    The CollectionJoin interface is the type of the result of joining to a collection over an association or element collection that has been specified as a Collection.
    The CommonAbstractCriteria interface defines functionality that is common to both top-level criteria queries and subqueries as well as to update and delete criteria operations.
    ComparableExpression<C extends Comparable<? super C>>
    Type for comparable query expressions.
    The CompoundSelection interface defines a compound selection item (a tuple, array, or result of a constructor).
    Used to construct criteria queries, compound selections, expressions, predicates, orderings.
    Interface used to build general case expressions.
    Interface used to build coalesce expressions.
    Interface used to build in predicates.
    Interface used to build simple case expressions.
    Used to specify how strings are trimmed.
    The CriteriaDelete interface defines functionality for performing bulk delete operations using the Criteria API
    The CriteriaQuery interface defines functionality that is specific to top-level queries.
    Abstracts over top-level queries and unions and intersections of top-level queries.
    Declares operations common to CriteriaUpdate and CriteriaDelete.
    The CriteriaUpdate interface defines functionality for performing bulk update operations using the Criteria API.
    Type for query expressions.
    Fetch<Z,X>
    Represents a join-fetched association or attribute.
    Represents an element of the from clause which may function as the parent of Fetches.
    From<Z,X>
    Represents a bound type, usually an entity that appears in the from clause, but may also be an embeddable belonging to an entity in the from clause.
    Join<Z,X>
    A join to an entity, embeddable, or basic type.
    Defines the three varieties of join.
    The ListJoin interface is the type of the result of joining to a collection over an association or element collection that has been specified as a List.
    Each instance represents a type of field which can be extracted from a LocalDate.
    Each instance represents a type of field which can be extracted from a LocalDateTime.
    Each instance represents a type of field which can be extracted from a LocalTime.
    MapJoin<Z,K,V>
    The MapJoin interface is the type of the result of joining to a collection over an association or element collection that has been specified as a Map.
    Specifies the precedence of null values within query result sets.
    Type for number query expressions.
    An object that defines an ordering over the query results.
    Type of criteria query parameter expressions.
    Path<X>
    Represents a simple or compound attribute path from a bound type or collection, and is a "primitive" expression.
    Type for collection query expressions.
    PluralJoin<Z,C,E>
    The PluralJoin interface defines functionality that is common to joins to all collection types.
    The type of a simple or compound predicate: a conjunction or disjunction of restrictions.
     
    Root<X>
    A root type in the from clause.
    The Selection interface defines an item that is to be returned in a query result.
    SetJoin<Z,E>
    The SetJoin interface is the type of the result of joining to a collection over an association or element collection that has been specified as a Set.
    The Subquery interface defines functionality that is specific to subqueries.
    TemporalExpression<T extends Temporal & Comparable<? super T>>
    Type for temporal query expressions.
    TemporalField<N, T extends Temporal>
    Each instance represents a type of field which can be extracted from a date, time, or datetime.
    Type for string query expressions.