Is it possible to disable this rule?
Yes and no. The default behavior as defined by the Bean Validation specification is to throw an exception. This has to do with the Liskov Substitution Principle. Have a look at the Method constraints in inheritance hierarchies section of the Bean Validation specification.
In sub types (be it sub classes/interfaces or interface implementations), no parameter constraints may be declared on overridden or implemented methods, nor may parameters be marked for cascaded validation. This would pose a strengthening of preconditions to be fulfilled by the caller.
Hibernate Validator is the reference implementation of Bean Validation and needs to adhere to these rules. However, the spec allows as a provider specific feature to relax these conditions. See also HV-872. HV-872 was just recently implemented and will be available in Hibernate Validator 5.3
If so how?
There will be a property hibernate.validator.allow_parameter_constraint_override which can be added to validation.xml to allow constraints in overriding methods. Note though, this will apply to all overriding constraints (there is no way to just do this for a single constraints) and this is a non portable feature. You should think twice, if you want to enable it. |