Annotates a parameter of a repository Find or Delete
method, indicating how an entity attribute is compared with the parameter's
value.
The @Is annotation's value() supplies the type of
comparison as a subtype of Constraint.
The By annotation must annotate the same parameter to indicate
the entity attribute name, or otherwise, if the -parameters compile
option is enabled, the persistent field is inferred by matching the name of
the method parameter.
For example,
@Repository
public interface Products extends CrudRepository<Product, Long> {
// Find Product entities where the price attribute is less than a maximum value.
@Find
List<Product> pricedBelow(@By(_Product.PRICE) @Is(LessThan.class) float max);
// Find a page of Product entities where the name field matches a pattern.
@Find
Page<Product> search(@By(_Product.NAME) @Is(Like.class) String pattern,
PageRequest pagination,
Order<Product> order);
// Remove Product entities with any of the unique identifiers listed.
@Delete
void remove(@By(ID) @Is(In.class) List<Long> productIds);
}
- Since:
- 1.1
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<? extends Constraint> A subtype ofConstraintthat indicates how the entity attribute is compared with a value.
-
Element Details
-
value
Class<? extends Constraint> valueA subtype of
Constraintthat indicates how the entity attribute is compared with a value.The constraint subtype must have a static method that accepts as its only parameter a value compatible with the type (or if primitive, a wrapper for the type) of the repository method parameter to which the
@Isannotation is applied. The repository method parameter type must also be consistent with the respective entity attribute type. This list indicates the constraint subtypes that can be used and links to the applicable static method for each:The following example involves a
Personentity that has abirthYearattribute of typeint. It compares the year in which a person was born against a minimum and maximum year that are supplied as parameters to a repository method:@Find @OrderBy(_Person.BIRTHYEAR) List<Person> bornWithin(@By(_Person.BIRTHYEAR) @Is(AtLeast.class) int minYear, @By(_Person.BIRTHYEAR) @Is(AtMost.class) int maxYear);The default constraint is the equality comparison.
- Returns:
- the type of comparison operation.
- Default:
jakarta.data.constraint.EqualTo.class
-