-
Couldn't load subscription status.
- Fork 3k
Introduce validation mode instead of a boolean flag for BV integration in ORM #46264
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
Introduce validation mode instead of a boolean flag for BV integration in ORM #46264
Conversation
|
/cc @gsmet (hibernate-orm) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| /** | ||
| * If a Bean Validation provider is present then behaves as if both {@link ValidationMode#CALLBACK} and | ||
| * {@link ValidationMode#DDL} modes are configured. Otherwise, same as {@link ValidationMode#NONE}. | ||
| */ | ||
| AUTO, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps get rid of this option and assume CALLBACK,DDL as the default value? It feels weird that you can select AUTO and other options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think AUTO makes perfect sense as we want things to be integrated automatically when HV is added. It's also in line with what people are used to in ORM.
A question though, @marko-bekhta , do we really get to NONE if HV is not around? I would have expected DDL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah... to apply the DDL ORM relies on the BV constraint metadata:
https://github.com/hibernate/hibernate-orm/blob/207a3637836d8405c140be8abcb0052284056eab/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java#L237
so if BV is not around, it won't work. If the user explicitly requests DDL/CALLBACK and BV is not there, things throw exceptions 😃. I think that comes from the spec here:
If a Bean Validation provider is present in the environment, the persistence provider must perform the automatic validation of entities. If no Bean Validation provider is present in the environment, no lifecycle event validation takes place. This is the default behavior.
and Hibernate ORM just adds on top of that the DDL mode 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok! Let’s just adjust the naming then and we should be fine.
| * Defines how the Bean Validation integration behaves. | ||
| */ | ||
| @WithDefault("AUTO") | ||
| Set<ValidationMode> modes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go with mode. It reads better and I don't think people will ever use two options at the same time, given auto does the job.
And even if you use two values, it's still the mode you want to use.
| /** | ||
| * Defines how the Bean Validation integration behaves. | ||
| */ | ||
| @WithDefault("AUTO") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using auto as that's what will appear as possible values in the doc.
| @WithDefault("AUTO") | |
| @WithDefault("auto") |
| /** | ||
| * If a Bean Validation provider is present then behaves as if both {@link ValidationMode#CALLBACK} and | ||
| * {@link ValidationMode#DDL} modes are configured. Otherwise, same as {@link ValidationMode#NONE}. | ||
| */ | ||
| AUTO, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think AUTO makes perfect sense as we want things to be integrated automatically when HV is added. It's also in line with what people are used to in ORM.
A question though, @marko-bekhta , do we really get to NONE if HV is not around? I would have expected DDL?
| if (!persistenceUnitConfig.validation().enabled()) { | ||
| descriptor.getProperties().setProperty(AvailableSettings.JAKARTA_VALIDATION_MODE, ValidationMode.NONE.name()); | ||
| } else { | ||
| descriptor.getProperties().setProperty( | ||
| AvailableSettings.JAKARTA_VALIDATION_MODE, | ||
| persistenceUnitConfig.validation().modes() | ||
| .stream() | ||
| .map(Enum::name) | ||
| .collect(Collectors.joining(","))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw.. do we want this to be included in the reactive processor? or reactive does not play nice with validation? (that was that other question that @yrodiere had: why does DDL work for reactive..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea, I haven't been involved in the Hibernate Reactive extension.
Either it's an oversight or it was not working. @DavideD would know better but, if we do implement it for HR also, I think it should be done in another PR anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged this one as that's something I want in 3.19. I let you discuss the situation in HR and see if it needs to be addressed in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #46327 for the Hibernate Reactive part.
…on in ORM as well as switch to AUTO instead of the CALLBACK to enable the DDL integration by default.
b4c7bd8 to
86ee3e3
Compare
Status for workflow
|
Status for workflow
|
|
Ah ah, you're awesome, I was going to ask for a migration guide entry but I see it was already in the description :). |

fixes #46034
I'm not sure about the property name itself ... I went with plural
quarkus.hibernate-orm.validation.modessince we can accept multiple values there... but maybe it should be singular insteadquarkus.hibernate-orm.validation.mode?As for the migration guide, I'd add something along the lines:
as to:
.... we do not set the property in the reactive processor so it is defaulted to
nullwhich in turn behaves asAUTOso bothCALLBACKandDDLwork:quarkus/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/HibernateReactiveProcessor.java
Lines 251 to 428 in 1bdd69f