BeanValidation works on normal Validations which are placed at FIELD-level:
@Email
@Column(unique = true)
private String email;
However, placing a custom constraint on TYPE-Level:
@Entity
@UniqueEmail
public class UserAccount {
@Email
@Column(unique = true)
private String email;
...
}
with the annotation being:
@Constraint(validatedBy = {UniqueEmailValidator.class})
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface UniqueEmail { ... }
will not work. The UniqueEmailValidator
is never called unless I programatically trigger it by calling .validate()
on an injected javax.validation.Validator
Is this expected behaviour or can that be changed in a way that the BeanValidation will also evaluate custom constraints on type level.