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.

  • Element Details

    • domain

      String domain
      Name 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<?>> uniquifier
      Class that converts values into unique objects (in the sense of equals() and hashCode()). Leave unset if the values themselves are sufficient for uniqueness (e.g., the objects themselves are unique under equals() comparison).
      Returns:
      unique object generator
      See Also:
      Default:
      org.dellroad.stuff.validation.DefaultUniquifier.class