Package org.dellroad.stuff.validation
Annotation Interface Unique
@Documented
@Constraint(validatedBy=UniqueValidator.class)
@Target({METHOD,FIELD,ANNOTATION_TYPE})
@Retention(RUNTIME)
public @interface Unique
Validation constraint that checks for the uniqueness of the constrained property's value over some uniqueness domain.
Uniqueness domains are identified by an arbitrary name; each domain is independent of the others.
By supplying a uniquifier() you can change the unique value associated with the constrained property;
by default, it is just the value of the property.
For this constraint to be effective, validation must be performed via
ValidationContext.validate().
This constraint will work on Collection or Map properties as well.
Note: null values are not considered, i.e., they are not required to be unique.
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>[]Class<? extends jakarta.validation.Payload>[]Class<? extends Uniquifier<?>>Class that converts values into unique objects (in the sense ofequals()andhashCode()).
-
Element Details
-
domain
String domainName of the uniqueness domain. Domains are identified by name. Different domains do not interact.- Returns:
- identifier for the uniqueness domain
-
-
-
message
String message- Default:
- "Value is not unique"
-
groups
Class<?>[] groups- Default:
- {}
-
payload
Class<? extends jakarta.validation.Payload>[] payload- Default:
- {}
-
uniquifier
Class<? extends Uniquifier<?>> uniquifierClass that converts values into unique objects (in the sense ofequals()andhashCode()). Leave unset if the values themselves are sufficient for uniqueness (e.g., the objects themselves are unique underequals()comparison).- Returns:
- unique object generator
- See Also:
- Default:
- org.dellroad.stuff.validation.DefaultUniquifier.class
-