-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
HHH-18724 Take constraint composition type into account when determining nullable state of a Column #9092
base: main
Are you sure you want to change the base?
Conversation
3c842b1
to
bafc6a8
Compare
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.
The pull request should target main
.
Also see my comments.
hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java
Outdated
Show resolved
Hide resolved
bafc6a8
to
48369e2
Compare
Thanks for your pull request! This pull request appears to follow the contribution rules. › This message was automatically generated. |
4cbef2e
to
0e343dc
Compare
hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java
Outdated
Show resolved
Hide resolved
0e343dc
to
8e99cf1
Compare
Found an edge case that needs fixing, will mark as draft for now. |
8e99cf1
to
d18bef8
Compare
Fixed edge case. Added a few more tests to ensure better test coverage. |
hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java
Outdated
Show resolved
Hide resolved
8e93c3d
to
14827c5
Compare
Thanks, looking good now. |
…ing nullable state of a Column
14827c5
to
4bdbb56
Compare
@@ -72,6 +75,9 @@ class TypeSafeActivator { | |||
|
|||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, TypeSafeActivator.class.getName() ); | |||
|
|||
private static final Map<Class<? extends Annotation>, Boolean> |
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.
Storing class references to application classes in a static field is unfortunately going to be a problem, unless you clean up the storage properly. Also, concurrent deployments could potentially run into race conditions, so I would suggest you use a ThreadLocal<Map<Class<? extends Annotation>, Boolean>>
instead and also make sure you clear it in a finally block within the activate
method.
boolean firstItem = true; | ||
boolean composedResultHasNotNull = false; |
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.
boolean firstItem = true; | |
boolean composedResultHasNotNull = false; | |
boolean composedResultHasNotNull = !useOrLogicForComposedConstraint; |
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.
This is what I initially had but it leads to an edge case when the first property is nullable in a composed constraint of type OR. (See test case I added for the Address.line3 property) In this case the result should be that the column should be considered nullable (nullable OR not-nullable => nullable) This is partly due to the fact that this function is applied recursively for constraints and I did not feel comfortable enough to completely change this. Thus resulting in this head/tail approach.
if ( firstItem ) { | ||
composedResultHasNotNull = hasNotNull; | ||
firstItem = false; | ||
} | ||
else if ( !useOrLogicForComposedConstraint ) { |
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.
if ( firstItem ) { | |
composedResultHasNotNull = hasNotNull; | |
firstItem = false; | |
} | |
else if ( !useOrLogicForComposedConstraint ) { | |
if ( !useOrLogicForComposedConstraint ) { |
https://hibernate.atlassian.net/browse/HHH-18724