Interface QuerySpecification<T>
- Type Parameters:
T
- The root entity type.
- All Known Subinterfaces:
MutationSpecification<T>
,SelectionSpecification<T>
- All Known Implementing Classes:
MutationSpecificationImpl
,SelectionSpecificationImpl
Commonality for all query specifications which allow iterative,
programmatic building of a query. A specification allows
restrictions,
sorting, and
fetching to be added to
a predefined HQL or criteria query.
createQuery(EntityManager)
obtains an executable query object associated with the given session.buildCriteria(CriteriaBuilder)
transforms the specification to acriteria query
.validate(CriteriaBuilder)
validates the query without executing it.
This is the abstract base type of SelectionSpecification
and MutationSpecification
.
- Since:
- 7.0
- API Note:
- Query specifications only support a single root entity.
-
Method Summary
Modifier and TypeMethodDescriptionbuildCriteria
(CriteriaBuilder builder) Build acriteria query
satisfying this specification, using the givenCriteriaBuilder
.createQuery
(EntityManager entityManager) Finalize the building and create executable query instance.createQuery
(Session session) Finalize the building and create executable query instance.createQuery
(StatelessSession session) Finalize the building and create executable query instance.Obtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference)
.restrict
(Restriction<? super T> restriction) Adds a restriction to the query specification.validate
(CriteriaBuilder builder) Validate the query.
-
Method Details
-
restrict
Adds a restriction to the query specification.- Parameters:
restriction
- The restriction predicate to be added.- Returns:
this
for method chaining.
-
createQuery
Finalize the building and create executable query instance. -
createQuery
Finalize the building and create executable query instance. -
createQuery
Finalize the building and create executable query instance. -
buildCriteria
Build acriteria query
satisfying this specification, using the givenCriteriaBuilder
.If the returned criteria query is mutated, the mutations will not be not reflected in this specification.
- Returns:
- a new criteria query
-
validate
Validate the query.- Returns:
this
if everything is fine- Throws:
Exception
- if it ain't all good
-
reference
TypedQueryReference<?> reference()Obtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference)
.
-