Interface MutationSpecification<T>
- Type Parameters:
T
- The entity type which is the target of the mutation.
- All Superinterfaces:
QuerySpecification<T>
- All Known Implementing Classes:
MutationSpecificationImpl
Specialization of
QuerySpecification
for programmatic customization of
mutation queries.
The method restrict(Restriction)
allows application of additional
filtering to the mutated entity. The static factory
methods of Restriction
are used to express filtering criteria of various
kinds.
MutationSpecification.create(Book.class, "delete from Book") .restrict(Restriction.lessThan(Book_.publicationDate, LocalDate.ofYearDay(2000,1))) .createQuery(session) .executeUpdate();
Once all restrictions are specified, call
createQuery()
to obtain an executable mutation query object.
- Since:
- 7.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A function capable of modifying or augmenting a criteria query. -
Method Summary
Modifier and TypeMethodDescriptionaugment
(MutationSpecification.Augmentation<T> augmentation) Add an augmentation to the specification.static <T> MutationSpecification<T>
create
(CriteriaDelete<T> criteriaDelete) Returns a specification reference which can be used to programmatically, iteratively build a MutationQuery based on the given criteria delete, allowing the addition of restrictions.static <T> MutationSpecification<T>
create
(CriteriaUpdate<T> criteriaUpdate) Returns a specification reference which can be used to programmatically, iteratively build a MutationQuery based on the given criteria update, allowing the addition of restrictions.static <T> MutationSpecification<T>
Returns a specification reference which can be used to programmatically, iteratively build a MutationQuery based on a base HQL statement, allowing the addition of restrictions.createQuery
(Session session) Finalize the building and create the MutationQuery instance.createQuery
(StatelessSession session) Finalize the building and create the MutationQuery 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.Methods inherited from interface org.hibernate.query.specification.QuerySpecification
buildCriteria, createQuery
-
Method Details
-
restrict
Description copied from interface:QuerySpecification
Adds a restriction to the query specification.- Specified by:
restrict
in interfaceQuerySpecification<T>
- Parameters:
restriction
- The restriction predicate to be added.- Returns:
this
for method chaining.
-
augment
Add an augmentation to the specification.- Parameters:
augmentation
- A function capable of modifying or augmenting a criteria query.- Returns:
this
for method chaining.
-
createQuery
Finalize the building and create the MutationQuery instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
-
createQuery
Finalize the building and create the MutationQuery instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
-
validate
Description copied from interface:QuerySpecification
Validate the query.- Specified by:
validate
in interfaceQuerySpecification<T>
- Returns:
this
if everything is fine
-
reference
TypedQueryReference<Void> reference()Description copied from interface:QuerySpecification
Obtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference)
.- Specified by:
reference
in interfaceQuerySpecification<T>
-
create
Returns a specification reference which can be used to programmatically, iteratively build a MutationQuery based on a base HQL statement, allowing the addition of restrictions.- Type Parameters:
T
- The root entity type for the mutation (the "target").mutationTarget
and<T>
are both expected to refer to the mutation target.- Parameters:
hql
- The base HQL query (expected to be anupdate
ordelete
query).mutationTarget
- The entity which is the target of the mutation.- Throws:
IllegalMutationQueryException
- Onlyupdate
anddelete
are supported; this method will throw an exception if the given HQL query is not anupdate
ordelete
.
-
create
Returns a specification reference which can be used to programmatically, iteratively build a MutationQuery based on the given criteria update, allowing the addition of restrictions.- Type Parameters:
T
- The root entity type for the mutation (the "target").- Parameters:
criteriaUpdate
- The criteria update query
-
create
Returns a specification reference which can be used to programmatically, iteratively build a MutationQuery based on the given criteria delete, allowing the addition of restrictions.- Type Parameters:
T
- The root entity type for the mutation (the "target").- Parameters:
criteriaDelete
- The criteria delete query
-