Hibernate Validator rejects constraints on a method that implements an interface
Fix it fast
Most common cause, 1 of 3The implementing method adds @Valid or constraints the interface does not have
Move the annotations up to the interface method and leave the implementation's parameters free of them.
public interface PetApi {
Pet addPet(@Valid @NotNull Pet pet);
}
@Service
@Validated
public class PetService implements PetApi {
@Override
public Pet addPet(Pet pet) { /* ... */ }
}Short answer
HV000151 means a method that overrides or implements another one declares parameter constraints or @Valid that are not exactly those of the supertype method. Keep the annotations only on the interface, strip them from the implementing class, or set hibernate.validator.allow_parameter_constraint_override when the interface is generated. Applies to Hibernate Validator 9.1 and Spring Boot 4.
Which cause do you have?
The message names two methods: the implementing one first, the interface or superclass one second. Print the parameter annotations of both and compare them side by side.
grep -n -A3 "addPet(" src/main/java/com/example/api/PetApi.java
grep -n -A3 "addPet(" src/main/java/com/example/web/PetController.javaThen find the line you see in this list and open its fix:
- 1The implementing method adds @Valid or constraints the interface does not have
The interface method has no constraint annotations on its parameters, while the controller or service method adds @Valid, @NotNull or similar - 2The implementation copies the interface annotations, but not all of them
Both methods carry annotations on the same parameter, but the sets differ, for example @Valid on both and @NotNull only on the interface - 3The interface comes from a generator or a library you cannot edit
The interface method named second in the message lives in generated sources or in a dependency jar, and the implementation needs its own constraints
What does the error look like?
jakarta.validation.ConstraintDeclarationExceptionHV000151: A method overriding another method must not redefine the parameter constraint configuration, but method <implementing method> redefines the configuration of <interface method>.
Cause 1 of 3
The implementing method adds @Valid or constraints the interface does not have
You seeThe interface method has no constraint annotations on its parameters, while the controller or service method adds @Valid, @NotNull or similar
Check
Hibernate Validator throws HV000151 when the overriding method is parameter-constrained and its configuration differs from the supertype method. A parameter marked @Valid counts as constrained just like one with @NotNull. The reference guide states that parameter constraints on an overriding method are not allowed even when the supertype declares none.
grep -rn "@Valid\|@NotNull\|@Size" src/main/java/com/example/web/PetController.javaFix
Move the annotations up to the interface method and leave the implementation's parameters free of them. Callers through the interface then see the same rules the implementation relies on.
public interface PetApi {
Pet addPet(@Valid @NotNull Pet pet);
}
@Service
@Validated
public class PetService implements PetApi {
@Override
public Pet addPet(Pet pet) { /* ... */ }
}Verify
The application starts, and calling the method with an invalid argument now ends in a constraint violation rather than HV000151.
mvn testConfirmed by docs.jboss.org
Cause 2 of 3
The implementation copies the interface annotations, but not all of them
You seeBoth methods carry annotations on the same parameter, but the sets differ, for example @Valid on both and @NotNull only on the interface
Check
The rule compares the full parameter configuration of both methods: the constraints on each parameter, any cross-parameter constraint and the @Valid cascade. Any difference, even a missing @NotNull, counts as redefining the configuration. An exact copy passes the check, yet it only repeats what the interface already says.
grep -n -B2 -A2 "Pet pet" src/main/java/com/example/api/PetApi.java src/main/java/com/example/web/PetController.javaFix
Delete the validation annotations from the implementing method's parameters and keep them in one place, the interface. Framework annotations that are not constraints can stay.
@Override
public Pet addPet(Pet pet) {
return repository.save(pet);
}Verify
The application context loads and validation still rejects a null or invalid Pet.
mvn testConfirmed by raw.githubusercontent.com
Cause 3 of 3
The interface comes from a generator or a library you cannot edit
You seeThe interface method named second in the message lives in generated sources or in a dependency jar, and the implementation needs its own constraints
Check
Section 12.3 of the reference guide lets Hibernate Validator relax the inheritance preconditions. The property hibernate.validator.allow_parameter_constraint_override is false by default, and the guide shows provider options being passed through Configuration#addProperty(). The guide also warns that the result no longer follows the specification.
grep -rn "interface PetApi" target/generated-sources src/main/javaFix
In Spring Boot 4, register a ValidationConfigurationCustomizer bean that adds the property to the Bean Validation configuration. Treat it as a deliberate exception, since subclasses may then demand more than the interface promises.
import org.springframework.boot.validation.autoconfigure.ValidationConfigurationCustomizer;
@Bean
ValidationConfigurationCustomizer allowParameterConstraintOverride() {
return configuration -> configuration.addProperty(
"hibernate.validator.allow_parameter_constraint_override", "true");
}Verify
The application starts with the constraints on the implementation, and an invalid call fails with a constraint violation.
mvn spring-boot:runConfirmed by docs.spring.io
How do I stop it coming back?
- Decide per API whether constraints live on the interface or on the class, and write it in the project README.
- Configure code generators to emit bean validation on the interface, so nobody adds it by hand on the controller.
- Give every validated service or controller method a test that calls it, because HV000151 is raised at runtime while Hibernate Validator builds metadata for the class, never by the compiler.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Dispatch Pro.