-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Integrate ORM REST Data Panache with Hibernate Validator #13307
Comments
/cc @FroMage, @gsmet, @loicmathieu |
Hibernate Validator ORM integration should be automatically enabled if present. Can you build a small reproducer? Thanks! |
Find the reproducer in this repository. Concretely, I have a small test that is failing because of this issue: https://github.com/Sgitario/beefy-scenarios/blob/baebdbde9d97f173ab02ac604b0ef133fba868b7/011-quarkus-panache-rest-flyway/src/test/java/io/quarkus/qe/PostgreSqlApplicationResourceTest.java#L68 Let me know if this is all you need. |
I have the following message:
so the Hibernate Validator integration is properly triggered. But you end up with a deeply wrapped exception:
I think there are several issues here:
@Sanne I think we should try to have someone from Arjuna to explain us why the warning? Then I don't really know what we could do to improve the wrapping... We could have all the default REST Panache methods throw a Another option could be to catch That being said, that would be a change in behavior compared to how things usually work. I don't really know if, in this case, the important thing is that we violated a constraint or if the transaction wasn't committed. The fact is that the constraints might be internal information that we don't really want to expose to the user. /cc @Sanne @FroMage @gytis I think this warrants a discussion. |
1/ ArC doesn't have to wrap, it can rethrow even checked exceptions. |
ArC does that only if they are in the list of thrown exceptions of the method. So if we keep it that way, as I mentioned it above, that means adding the |
You're telling me what it does ATM, and I'm saying it doesn't have to. If the method throws an undeclared checked exception, it is most likely due to an interceptor. Either it's wrong and the interceptor should be corrected, or it's fine, and ArC should not get in the way and wrap it. |
This has |
@rsvoboda +1, done for the labels. Need to think about the description, this one is complicated. |
I have recently updated I could similarly map a validation constraint violation to HTTP 400 error here: https://github.com/quarkusio/quarkus/blob/master/extensions/panache/hibernate-orm-rest-data-panache/runtime/src/main/java/io/quarkus/hibernate/orm/rest/data/panache/runtime/RestDataPanacheExceptionMapper.java#L31. |
Description
I think it would really useful to integrate the ORM REST Data Panache module with the Hibernate Validator extension.
Implementation ideas
I've tried to implement a workaround by using the annotations, but I could not make this integration worked.
The modules that I used are:
My resource:
And my entity:
When I add an application with an empty name, I got a 500 Internal Server Error because the name is not nullable which is expected, but not nice as I annotated the name field as not empty, therefore I should have received 400 Bad Request.
The only current way to implement this is manually using the validation service, but I would be nice to have something like:
Or even validate the entities always only if the hibernate-validator extension does exist in the classpath.
The text was updated successfully, but these errors were encountered: