-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
@NotNull
does not add not null
to persistence unit
#46034
Comments
/cc @geoand (kotlin) |
Hello, Thanks for reporting, and for the reproducer. It does seem there is a problem with I checked that it's not related to:
For the person doing further investigation (maybe me, maybe not):
It's just a guess, but I suspect that, in Quarkus, that integrator gets triggered too late. Dev UI code relies on |
@yrodiere does that mean that even though the not null may not properly be reflected in the dev UI (which is of course still a problem, especially since we use it to populate flyway), Hibernate still adds Also for the |
I didn't check. That's possible. Though if I had to bet, I'd rather go for the option "it doesn't work either way, but for different reasons" 😅
Yep, I use Linux as well, that's why I removed |
@yrodiere what is the status of this issue? Is there still a plan to look into this issue? Since it is quite annoying for our team. |
It's in the backlog, someone will look into it when they have time. Not the only issue to work on unfortunately. If your team want to speed things up, both Quarkus and Hibernate ORM gladly welcome contributions -- just make sure to tell us you're working on this. |
hey, Lines 1106 to 1115 in 046dc99
I'd suggest using Flyway/Liquibase for production-kind applications to manage the schema. |
True, but we do allow Hibernate ORM to generate the first iteration of the schema and use it as a Flyway script, and we do allow validating the (Flyway-managed) schema with Hibernate ORM, both of which are reasonable and would be affected by this behavior.
Given your explanation, it makes sense... but the report mentions this is a regression compared to previous versions... ? Something changed in this area, didn't it? Was DDL the default previously, and we changed it to CALLBACK by accident? Should we consider allowing to pick DDL explicitly, or using it by default? |
I think it was always set to |
This is a really important point. Also for us, we use the dev UI persistence unit's create script to upgrade our initial flyway-managed scheme, so if our scheme has to deviate from what Hibernate generates, it becomes extremely cumbersome to update the initial script for products that have not been released yet (and thus we can still update the initial migration). |
So about this, I looked a bit further into it and it seems that it happened when we switched from Hibernate reactive to Hibernate ORM. I'm not necessarily sure something changed in previous versions anymore, I think it's simply that the not null works for Hibernate reactive, but not for Hibernate ORM. I have no clue why this would have worked for reactive then, maybe someone has an idea about that? |
from the ORM side, from what I see both DDL and AUTO would apply the constraint to the schema, but what seems more applicable for this case: Hibernate ORM allows passing multiple values here, so maybe let's just pass |
I think the DDL part should be configurable, because it's not uncommon for apps to have "incorrect" existing data (does't comply with So, +1 to allow adding Also we'd need to see what's different in Hibernate Reactive... |
I think we should have a configuration property. And I would default to We could deprecate the existing property, make it optional and disable BV integration if set to false. |
@gsmet for my understanding (and maybe for a bit of context if someone reads this issue): What does |
Ah yes sorry, It's Bean Validation and Hibernate Validator (a Bean Validation implementation). |
Describe the bug
With Hibernate ORM, we have an entity that has a
@NotNull
annotation. According to documentation, Hibernate should pick this up and addnot null
to the column in the Persistent Unit. However, when you do that on Quarkus 3.18.1,not null
is not added to the persistence unit.This used to be properly applied, until at some point we discovered after a few Quarkus updates that this suddenly no longer happens, so I am not sure in which version this stopped working.
I made a small reproducer at https://gitlab.com/l.s.andringa1/quarkus-hibernate-non-null-reproducer
The project is in Kotlin since that is what we are used to. I am not sure whether it only happens on Kotlin or also on Java. I tried to put both kotlin and java entities in the same project to test, but it was not added to the same persistence unit.
Expected behavior
When
@NotNull
is added to an entity, as follows:The persistence unit (for MariaDB in this case) should look like:
Actual behavior
When
@NotNull
is added to an entity, as follows:The persistence unit looks as follows:
How to Reproduce?
Reproducer:
Output of
uname -a
orver
Windows 11 (Also tested on Ubuntu 24.10)
Output of
java -version
OpenJDK Runtime Environment Corretto-21.0.5.11.1
Quarkus version or git rev
3.18.1
Build tool (ie. output of
mvnw --version
orgradlew --version
)Gradle 8.12.1
Additional information
No response
The text was updated successfully, but these errors were encountered: