HHH-17290 Embeddable with a primitive field cannot be set to null
This commit is contained in:
parent
583015100b
commit
e5b2298b76
|
@ -881,8 +881,7 @@ public class AnnotatedColumn {
|
|||
// }
|
||||
//not following the spec but more clean
|
||||
if ( nullability != Nullability.FORCED_NULL
|
||||
&& inferredData.getClassOrElement().isPrimitive()
|
||||
&& !inferredData.getProperty().isArray() ) {
|
||||
&& !PropertyBinder.isOptional( inferredData.getProperty(), propertyHolder ) ) {
|
||||
column.setNullable( false );
|
||||
}
|
||||
final String propertyName = inferredData.getPropertyName();
|
||||
|
|
|
@ -451,7 +451,7 @@ public class PropertyBinder {
|
|||
|
||||
private void handleOptional(Property property) {
|
||||
if ( this.property != null ) {
|
||||
property.setOptional( !isId && isOptional( this.property ) );
|
||||
property.setOptional( !isId && isOptional( this.property, this.holder ) );
|
||||
if ( property.isOptional() ) {
|
||||
final OptionalDeterminationSecondPass secondPass = persistentClasses -> {
|
||||
// Defer determining whether a property and its columns are nullable,
|
||||
|
@ -1200,10 +1200,12 @@ public class PropertyBinder {
|
|||
* Should this property be considered optional, taking into
|
||||
* account whether it is primitive?
|
||||
*/
|
||||
private static boolean isOptional(XProperty property) {
|
||||
public static boolean isOptional(XProperty property, PropertyHolder propertyHolder) {
|
||||
return property.isAnnotationPresent( Basic.class )
|
||||
? property.getAnnotation( Basic.class ).optional()
|
||||
: property.isArray() || !property.getClassOrElementClass().isPrimitive();
|
||||
: property.isArray()
|
||||
|| propertyHolder != null && propertyHolder.isComponent()
|
||||
|| !property.getClassOrElementClass().isPrimitive();
|
||||
}
|
||||
|
||||
private static boolean isLazy(XProperty property) {
|
||||
|
|
|
@ -533,7 +533,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen
|
|||
Object owner,
|
||||
Map<Object, Object> copyCache) {
|
||||
|
||||
if ( original == null && target == null ) {
|
||||
if ( original == null ) {
|
||||
return null;
|
||||
}
|
||||
if ( compositeUserType != null ) {
|
||||
|
@ -570,7 +570,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen
|
|||
Map<Object, Object> copyCache,
|
||||
ForeignKeyDirection foreignKeyDirection) {
|
||||
|
||||
if ( original == null && target == null ) {
|
||||
if ( original == null ) {
|
||||
return null;
|
||||
}
|
||||
if ( compositeUserType != null ) {
|
||||
|
|
Loading…
Reference in New Issue