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.
CriteriaBuilderis the entry point for constructing queries, expressions, predicates, projections, and ordering criteria.CriteriaQueryrepresents a top-level query slection query.CriteriaUpdateandCriteriaDeleterepresents update and delete statements, respectively.Expressionand its subtypes represent expressions of various types.Selectionrepresents a projected value in a query result list.Orderrepresents 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
-
ClassDescriptionThe
AbstractQueryinterface 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.CollectionJoin<Z,E> TheCollectionJoininterface is the type of the result of joining to a collection over an association or element collection that has been specified as aCollection.TheCommonAbstractCriteriainterface 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.TheCompoundSelectioninterface 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.TheCriteriaDeleteinterface defines functionality for performing bulk delete operations using the Criteria APITheCriteriaQueryinterface defines functionality that is specific to top-level queries.Declares operations common toCriteriaUpdateandCriteriaDelete.TheCriteriaUpdateinterface defines functionality for performing bulk update operations using the Criteria API.Expression<T>Type for query expressions.Fetch<Z,X> Represents a join-fetched association or attribute.FetchParent<Z,X> 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.ListJoin<Z,E> TheListJoininterface is the type of the result of joining to a collection over an association or element collection that has been specified as aList.Each instance represents a type of field which can be extracted from aLocalDate.Each instance represents a type of field which can be extracted from aLocalDateTime.Each instance represents a type of field which can be extracted from aLocalTime.MapJoin<Z,K, V> TheMapJoininterface is the type of the result of joining to a collection over an association or element collection that has been specified as aMap.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.PluralExpression<C,E> Type for collection query expressions.PluralJoin<Z,C, E> ThePluralJoininterface 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.Selection<X>TheSelectioninterface defines an item that is to be returned in a query result.SetJoin<Z,E> TheSetJoininterface is the type of the result of joining to a collection over an association or element collection that has been specified as aSet.Subquery<T>TheSubqueryinterface defines functionality that is specific to subqueries.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.