HHH-16937 Handle optional `@Any` and discriminator/key nullability
This commit is contained in:
parent
b99d914d14
commit
c72efeb92d
|
@ -101,6 +101,10 @@ public @interface Any {
|
|||
|
||||
/**
|
||||
* Whether the association is optional.
|
||||
* <p>
|
||||
* If the discriminator {@link jakarta.persistence.Column Column} or the
|
||||
* {@link jakarta.persistence.JoinColumn JoinColumn} are not nullable the
|
||||
* association is always considered non-optional, regardless of this value.
|
||||
*
|
||||
* @return {@code false} if the association cannot be null.
|
||||
*/
|
||||
|
|
|
@ -94,6 +94,7 @@ public class AnyBinder {
|
|||
}
|
||||
|
||||
final boolean lazy = any.fetch() == FetchType.LAZY;
|
||||
final boolean optional = any.optional();
|
||||
final Any value = BinderHelper.buildAnyValue(
|
||||
property.getAnnotation( Column.class ),
|
||||
getOverridableAnnotation( property, Formula.class, context ),
|
||||
|
@ -104,7 +105,7 @@ public class AnyBinder {
|
|||
nullability,
|
||||
propertyHolder,
|
||||
entityBinder,
|
||||
any.optional(),
|
||||
optional,
|
||||
context
|
||||
);
|
||||
|
||||
|
@ -121,6 +122,7 @@ public class AnyBinder {
|
|||
binder.setCascade( cascadeStrategy );
|
||||
binder.setBuildingContext( context );
|
||||
Property prop = binder.makeProperty();
|
||||
prop.setOptional( optional && value.isNullable() );
|
||||
//composite FK columns are in the same table, so it's OK
|
||||
propertyHolder.addProperty( prop, columns, inferredData.getDeclaringClass() );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue