Hibernate validation for multi module case: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint

See original GitHub issue

When 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

  1. git clone https://github.com/asodja/quarkus-multimodule-hibernate
  2. Run MyResourceTest.java -> both tests fail, response is 500
  3. Uncomment dummy method with @NotBlank annotation in MyResource.java
  4. 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
gsmetcommented, Nov 12, 2020

Frankly, just add the Jandex index creation to your build. Anything else will be brittle.

0reactions
gsmetcommented, Mar 10, 2022

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:

@gsmet https://github.com/gsmet I am, yes, I haven’t changed anything. But while building a small, separate reproducer I noticed that it actually works as expected so it looks like there’s something wrong with my actual project. Happily (or sadly…) I only have to figure out what.

Thanks for the fast reply!

— Reply to this email directly, view it on GitHub https://github.com/quarkusio/quarkus/issues/13233#issuecomment-1063893822, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJYOBKS6CRHBRG55C2ZQSDU7HEJNANCNFSM4TSARPLQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found