HHH-16600 @Basic(optional=false) on embeddable held by single table subclass

don't generate a 'not null' constraint for a field of an embeddable class if
it belongs to a subclass in single table inheritance hierarchy
This commit is contained in:
Gavin 2023-05-24 20:02:55 +02:00 committed by Gavin King
parent 84547e8f4c
commit 5efa49f7d1
1 changed files with 5 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
import org.hibernate.property.access.internal.PropertyAccessStrategyCompositeUserTypeImpl;
import org.hibernate.property.access.internal.PropertyAccessStrategyMixedImpl;
@ -368,7 +369,10 @@ public class EmbeddableBinder {
for ( PropertyData propertyAnnotatedElement : classElements ) {
processElementAnnotations(
subholder,
isNullable ? Nullability.NO_CONSTRAINT : Nullability.FORCED_NOT_NULL,
entityBinder.getPersistentClass() instanceof SingleTableSubclass
// subclasses in single table inheritance can't have not null constraints
? Nullability.FORCED_NULL
: ( isNullable ? Nullability.NO_CONSTRAINT : Nullability.FORCED_NOT_NULL ),
propertyAnnotatedElement,
new HashMap<>(),
entityBinder,