Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combination Hibernate Validation advice to use @ApplicationScoped does not work. #18763

Closed
sjaakd opened this issue Jul 16, 2021 · 8 comments · Fixed by #18935
Closed

Combination Hibernate Validation advice to use @ApplicationScoped does not work. #18763

sjaakd opened this issue Jul 16, 2021 · 8 comments · Fixed by #18935
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/question Further information is requested
Milestone

Comments

@sjaakd
Copy link

sjaakd commented Jul 16, 2021

Describe the bug

If there are multiple occurrences of a custom annotation, it seems that there's only one initialized. This is not the case in for instance JBOSS and leads to unexpected behavior.

I also tried @singleton, same result.

Expected behavior

The annotation is initialized with the correct annotation proxy instance before the isValid is executed.

Actual behavior

It is not. First come, first serve.

How to Reproduce?

https://github.com/sjaakd/reproducer_hv

Steps to reproduce:
http://localhost:8080/reproducer/q/swagger-ui/#/default/example

Note the validated Request:

    @AlwaysInvalid
    private String field1;

    @AlwaysInvalid( defaultState = "test ")
    private String field2;

The validator implementation is supposed to select the injected dao if defaulState is not set.

Output of uname -a or ver

No response

Output of java -version

java 11

GraalVM version (if different from Java)

Quarkus version or git rev

1.12.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

maven, intellij

Additional information

none

@sjaakd sjaakd added the kind/bug Something isn't working label Jul 16, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 16, 2021

/cc @Sanne, @gsmet, @yrodiere

@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Jul 16, 2021
@geoand
Copy link
Contributor

geoand commented Jul 21, 2021

Quarkus 1.12.1.Final is pretty old by now, can you try 1.13.7.Final and / or 2.0.2.Final?

@gsmet
Copy link
Member

gsmet commented Jul 21, 2021

This is expected. You made your AlwaysInvalidValidator bean @ApplicationScoped so only one will be created for the whole application.

If you make it @Dependent, the problem goes away.

@gsmet gsmet closed this as completed Jul 21, 2021
@gsmet gsmet added kind/question Further information is requested and removed kind/bug Something isn't working labels Jul 21, 2021
@sjaakd
Copy link
Author

sjaakd commented Jul 21, 2021

This is expected. You made your AlwaysInvalidValidator bean @ApplicationScoped so only one will be created for the whole application.

If you make it @Dependent, the problem goes away.

I understand.. but I think the behavior on JBOSS looks different that in Quarkus (our validators are shared). That is portability issue. I'll check if I can adapt in JBOSS as well. I can't find where, but I read somewhere that the advice was to use @ApplictionScoped on custom validators.

Besides this example, I could not get non @ApplicationScoped validators to function earlier.

@sjaakd
Copy link
Author

sjaakd commented Jul 21, 2021

Quarkus 1.12.1.Final is pretty old by now, can you try 1.13.7.Final and / or 2.0.2.Final?

I would really like to, but #18587 is blocking me.

@Sanne
Copy link
Member

Sanne commented Jul 21, 2021

I can't find where, but I read somewhere that the advice was to use @ApplictionScoped on custom validators.

I really don't know about that, but I'd suggest to trust @gsmet over other random suggestions as he's the project lead for Hibernate Validator and also responsible for its maintenance in JBoss server ;-)

@gsmet
Copy link
Member

gsmet commented Jul 21, 2021

Well, @ApplicationScoped is recommended IF your bean can be shared as you then have only one instance.

It's definitely not recommended if you need different ConstraintValidator beans.

@gsmet
Copy link
Member

gsmet commented Jul 22, 2021

@sjaakd I created #18935 to clarify this. Thanks for the report!

@quarkus-bot quarkus-bot bot added this to the 2.2 - main milestone Jul 22, 2021
@gsmet gsmet modified the milestones: 2.2 - main, 2.1.1.Final Aug 3, 2021
gsmet added a commit to gsmet/quarkus that referenced this issue Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants