Package org.hibernate.query.restriction
Interface Restriction<X>
- Type Parameters:
X
- The entity result type of the query
A rule for restricting query results. This allows restrictions to be added to
a
QuerySpecification
by calling
restrict()
.
SelectionSpecification.create(Book.class) .restrict(Restriction.like(Book_.title, "%Hibernate%", false)) .restrict(Restriction.greaterThan(Book_.pages, 100)) .sort(Order.desc(Book_.title)) .createQuery(session) .getResultList();
Each restriction pairs an attribute of the
entity with a Range
of allowed values for the attribute.
A parameter of a finder method or HQL query method may be declared with type Restriction<? super E>
,
List<Restriction<? super E>>
, or Restriction<? super E>...
(varargs) where E
is the entity type returned by the query.
To create a Restriction
on a compound path, use Path
.
- Since:
- 7.0
- See Also:
- API Note:
- This class is similar to
jakarta.data.Restriction
, and is used by Hibernate Data Repositories to implement Jakarta Data query methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Restriction<T>
all
(List<? extends Restriction<? super T>> restrictions) Combine the given restrictions using logical and.static <T> Restriction<T>
all
(Restriction<? super T>... restrictions) Combine the given restrictions using logical and.default Restriction<X>
and
(Restriction<X> restriction) Combine this restriction with the given restriction using logical and.static <T> Restriction<T>
any
(List<? extends Restriction<? super T>> restrictions) Combine the given restrictions using logical or.static <T> Restriction<T>
any
(Restriction<? super T>... restrictions) Combine the given restrictions using logical or.default void
apply
(CriteriaQuery<?> query, Root<? extends X> root) Apply this restriction to the given root entity of the given criteria query.static <T,
U extends Comparable<U>>
Restriction<T>between
(SingularAttribute<T, U> attribute, U lowerBound, U upperBound) Restrict the given attribute to fall between the given values.static <T> Restriction<T>
contains
(SingularAttribute<T, String> attribute, String substring) Restrict the given attribute to contain the given substring.static <T> Restriction<T>
contains
(SingularAttribute<T, String> attribute, String substring, boolean caseSensitive) Restrict the given attribute to contain the given substring, explicitly specifying case sensitivity.static <T> Restriction<T>
endsWith
(SingularAttribute<T, String> attribute, String suffix) Restrict the given attribute to end with the given string suffix.static <T> Restriction<T>
endsWith
(SingularAttribute<T, String> attribute, String suffix, boolean caseSensitive) Restrict the given attribute to end with the given string suffix, explicitly specifying case sensitivity.static <T,
U> Restriction<T> equal
(SingularAttribute<T, U> attribute, U value) Restrict the given attribute to be exactly equal to the given value.static <T> Restriction<T>
equalIgnoringCase
(SingularAttribute<T, String> attribute, String value) Restrict the given attribute to be equal to the given string, ignoring case.static <T,
U extends Comparable<U>>
Restriction<T>greaterThan
(SingularAttribute<T, U> attribute, U lowerBound) Restrict the given attribute to be strictly greater than the given lower bound.static <T,
U extends Comparable<U>>
Restriction<T>greaterThanOrEqual
(SingularAttribute<T, U> attribute, U lowerBound) Restrict the given attribute to be greater than or equal to the given lower bound.static <T,
U> Restriction<T> in
(SingularAttribute<T, U> attribute, List<U> values) Restrict the given attribute to be exactly equal to one of the given values.static <T,
U> Restriction<T> in
(SingularAttribute<T, U> attribute, U... values) Restrict the given attribute to be exactly equal to one of the given values.static <T,
U extends Comparable<U>>
Restriction<T>lessThan
(SingularAttribute<T, U> attribute, U upperBound) Restrict the given attribute to be strictly less than the given upper bound.static <T,
U extends Comparable<U>>
Restriction<T>lessThanOrEqual
(SingularAttribute<T, U> attribute, U upperBound) Restrict the given attribute to be less than or equal to the given upper bound.static <T> Restriction<T>
like
(SingularAttribute<T, String> attribute, String pattern) Restrict the given attribute to match the given pattern.static <T> Restriction<T>
like
(SingularAttribute<T, String> attribute, String pattern, boolean caseSensitive) Restrict the given attribute to match the given pattern, explicitly specifying case sensitivity.static <T> Restriction<T>
like
(SingularAttribute<T, String> attribute, String pattern, boolean caseSensitive, char charWildcard, char stringWildcard) Restrict the given attribute to match the given pattern, explicitly specifying case sensitivity, along with single-character and multi-character wildcards.negated()
Negate this restriction.static <T,
U extends Comparable<U>>
Restriction<T>notBetween
(SingularAttribute<T, U> attribute, U lowerBound, U upperBound) Restrict the given attribute to not fall between the given values.static <T> Restriction<T>
notContains
(SingularAttribute<T, String> attribute, String substring) Restrict the given attribute to not contain the given substring.static <T> Restriction<T>
notContains
(SingularAttribute<T, String> attribute, String substring, boolean caseSensitive) Restrict the given attribute to not contain the given substring, explicitly specifying case sensitivity.static <T,
U> Restriction<T> notIn
(SingularAttribute<T, U> attribute, List<U> values) Restrict the given attribute to be not equal to any of the given values.static <T,
U> Restriction<T> notIn
(SingularAttribute<T, U> attribute, U... values) Restrict the given attribute to be not equal to any of the given values.static <T> Restriction<T>
notLike
(SingularAttribute<T, String> attribute, String pattern) Restrict the given attribute to not match the given pattern.static <T> Restriction<T>
notLike
(SingularAttribute<T, String> attribute, String pattern, boolean caseSensitive) Restrict the given attribute to not match the given pattern, explicitly specifying case sensitivity.static <T,
U> Restriction<T> notNull
(SingularAttribute<T, U> attribute) Restrict the given attribute to be non-null.default Restriction<X>
or
(Restriction<X> restriction) Combine this restriction with the given restriction using logical or.static <T,
U> Restriction<T> restrict
(SingularAttribute<T, U> attribute, Range<U> range) Restrict the allowed values of the given attribute to the given range.static <T> Restriction<T>
Restrict the allowed values of the named attribute of the given entity class to the given range.static <T> Restriction<T>
startsWith
(SingularAttribute<T, String> attribute, String prefix) Restrict the given attribute to start with the given string prefix.static <T> Restriction<T>
startsWith
(SingularAttribute<T, String> attribute, String prefix, boolean caseSensitive) Restrict the given attribute to start with the given string prefix, explicitly specifying case sensitivity.toPredicate
(Root<? extends X> root, CriteriaBuilder builder) Return a JPA CriteriaPredicate
constraining the given root entity by this restriction.static <T,
U> Restriction<T> unequal
(SingularAttribute<T, U> attribute, U value) Restrict the given attribute to be not equal to the given value.static <T> Restriction<T>
An empty restriction.
-
Method Details
-
negated
Restriction<X> negated()Negate this restriction. -
or
Combine this restriction with the given restriction using logical or.- See Also:
-
and
Combine this restriction with the given restriction using logical and.- See Also:
-
toPredicate
Return a JPA CriteriaPredicate
constraining the given root entity by this restriction. -
apply
Apply this restriction to the given root entity of the given criteria query. -
restrict
Restrict the allowed values of the given attribute to the given range. -
restrict
Restrict the allowed values of the named attribute of the given entity class to the given range.This operation is not compile-time type safe. Prefer the use of
restrict(SingularAttribute, Range)
. -
equal
Restrict the given attribute to be exactly equal to the given value.- See Also:
-
unequal
Restrict the given attribute to be not equal to the given value. -
equalIgnoringCase
Restrict the given attribute to be equal to the given string, ignoring case.- See Also:
-
in
Restrict the given attribute to be exactly equal to one of the given values.- See Also:
-
notIn
Restrict the given attribute to be not equal to any of the given values. -
in
Restrict the given attribute to be exactly equal to one of the given values.- See Also:
-
notIn
Restrict the given attribute to be not equal to any of the given values. -
between
static <T,U extends Comparable<U>> Restriction<T> between(SingularAttribute<T, U> attribute, U lowerBound, U upperBound) Restrict the given attribute to fall between the given values.- See Also:
-
notBetween
static <T,U extends Comparable<U>> Restriction<T> notBetween(SingularAttribute<T, U> attribute, U lowerBound, U upperBound) Restrict the given attribute to not fall between the given values. -
greaterThan
static <T,U extends Comparable<U>> Restriction<T> greaterThan(SingularAttribute<T, U> attribute, U lowerBound) Restrict the given attribute to be strictly greater than the given lower bound.- See Also:
-
lessThan
static <T,U extends Comparable<U>> Restriction<T> lessThan(SingularAttribute<T, U> attribute, U upperBound) Restrict the given attribute to be strictly less than the given upper bound.- See Also:
-
greaterThanOrEqual
static <T,U extends Comparable<U>> Restriction<T> greaterThanOrEqual(SingularAttribute<T, U> attribute, U lowerBound) Restrict the given attribute to be greater than or equal to the given lower bound.- See Also:
-
lessThanOrEqual
static <T,U extends Comparable<U>> Restriction<T> lessThanOrEqual(SingularAttribute<T, U> attribute, U upperBound) Restrict the given attribute to be less than or equal to the given upper bound.- See Also:
-
like
static <T> Restriction<T> like(SingularAttribute<T, String> attribute, String pattern, boolean caseSensitive, char charWildcard, char stringWildcard) Restrict the given attribute to match the given pattern, explicitly specifying case sensitivity, along with single-character and multi-character wildcards.- Parameters:
pattern
- A pattern involving the given wildcard characterscaseSensitive
-true
if matching is case-sensitivecharWildcard
- A wildcard character which matches any single characterstringWildcard
- A wildcard character which matches any string of characters- See Also:
-
like
static <T> Restriction<T> like(SingularAttribute<T, String> attribute, String pattern, boolean caseSensitive) Restrict the given attribute to match the given pattern, explicitly specifying case sensitivity. The pattern must be expressed in terms of the default wildcard characters_
and%
.- Parameters:
pattern
- A pattern involving the default wildcard characterscaseSensitive
-true
if matching is case-sensitive- See Also:
-
like
Restrict the given attribute to match the given pattern. The pattern must be expressed in terms of the default wildcard characters_
and%
.- See Also:
-
notLike
Restrict the given attribute to not match the given pattern. The pattern must be expressed in terms of the default wildcard characters_
and%
.- See Also:
-
notLike
static <T> Restriction<T> notLike(SingularAttribute<T, String> attribute, String pattern, boolean caseSensitive) Restrict the given attribute to not match the given pattern, explicitly specifying case sensitivity. The pattern must be expressed in terms of the default wildcard characters_
and%
.- Parameters:
pattern
- A pattern involving the default wildcard characterscaseSensitive
-true
if matching is case-sensitive
-
startsWith
Restrict the given attribute to start with the given string prefix.- See Also:
-
endsWith
Restrict the given attribute to end with the given string suffix.- See Also:
-
contains
Restrict the given attribute to contain the given substring.- See Also:
-
notContains
Restrict the given attribute to not contain the given substring. -
startsWith
static <T> Restriction<T> startsWith(SingularAttribute<T, String> attribute, String prefix, boolean caseSensitive) Restrict the given attribute to start with the given string prefix, explicitly specifying case sensitivity.- See Also:
-
endsWith
static <T> Restriction<T> endsWith(SingularAttribute<T, String> attribute, String suffix, boolean caseSensitive) Restrict the given attribute to end with the given string suffix, explicitly specifying case sensitivity.- See Also:
-
contains
static <T> Restriction<T> contains(SingularAttribute<T, String> attribute, String substring, boolean caseSensitive) Restrict the given attribute to contain the given substring, explicitly specifying case sensitivity.- See Also:
-
notContains
static <T> Restriction<T> notContains(SingularAttribute<T, String> attribute, String substring, boolean caseSensitive) Restrict the given attribute to not contain the given substring, explicitly specifying case sensitivity. -
notNull
Restrict the given attribute to be non-null. -
all
Combine the given restrictions using logical and. -
any
Combine the given restrictions using logical or. -
all
Combine the given restrictions using logical and. -
any
Combine the given restrictions using logical or. -
unrestricted
An empty restriction.
-