Hibernate validation for multi module case: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint
See original GitHub issueWhen using hibernate validation and @Valid with request body parameter, I got an 500 when Pojo I am validating is not in a module that Quarkus scans. My Pojo class has annotation @NotBlank but I get:
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'hello.arg0.value'
If I add @NotBlank anywhere in module that Quarkus scans it works ok and pojo gets validated and I get 400 if it is invalid or 200 if it is valid.
I don’t want that my lib module is scanned, since there are a lot of things in there.
Expected behavior Pojo is validated normally, I get 400 if it is not valid or 200 if it is valid.
Actual behavior javax.validation.UnexpectedTypeException is thrown.
To Reproduce
- git clone https://github.com/asodja/quarkus-multimodule-hibernate
- Run
MyResourceTest.java-> both tests fail, response is 500 - Uncomment dummy method with
@NotBlankannotation inMyResource.java - Run
MyResourceTest.java-> both tests pass, response is 400 and 200 as expected
Environment (please complete the following information):
- Output of
java -version: openjdk version “1.8.0_242” - Quarkus version: 1.9.2.Final
- Build tool: Gradle 6.6.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Top Results From Across the Web
HV000030: No validator could be found for constraint 'javax ...
I got a similiar error but ...Constraints.NotEmpty' validating type 'java.lang.Long'. It happened because I was using @NotEmpty in a ...
Read more >No validator could be found for constraint - HowToDoInJava
1) Problem. UnexpectedTypeException error you will get when you are trying to use incorrect hibernate validator annotation on any bean property.
Read more >Hibernate Validator 8.0.0.Final - Jakarta Bean Validation ...
The validate() method returns a set of ConstraintViolation instances, which you can iterate over in order to see which validation errors ...
Read more >Value extraction for cascaded validation and type argument ...
Constraints can be applied to type arguments (of bean properties, ... In case an illegal value extractor definition is detected, ...
Read more >Validation with Hibernate Validator - Quarkus
NotBlank; import javax.validation.constraints.Min; public class Book { @NotBlank(message="Title may not be blank") public String title; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Frankly, just add the Jandex index creation to your build. Anything else will be brittle.
Make sure you really have a Jandex index for the modules in which the constraints are.
Because we take the list of constraints we detect in the Jandex index and we push it to HV. Any constraint that is not in the Jandex index won’t have its validators registered in HV. Which would lead to the errors you are seeing.
On Thu, Mar 10, 2022 at 11:21 AM moisaluc @.***> wrote: