File tree Expand file tree Collapse file tree 3 files changed +8
-7
lines changed
hibernate-core/src/main/java/org/hibernate Expand file tree Collapse file tree 3 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -881,8 +881,7 @@ private static AnnotatedColumns buildImplicitColumn(
881
881
// }
882
882
//not following the spec but more clean
883
883
if ( nullability != Nullability .FORCED_NULL
884
- && inferredData .getClassOrElement ().isPrimitive ()
885
- && !inferredData .getProperty ().isArray () ) {
884
+ && !PropertyBinder .isOptional ( inferredData .getProperty (), propertyHolder ) ) {
886
885
column .setNullable ( false );
887
886
}
888
887
final String propertyName = inferredData .getPropertyName ();
Original file line number Diff line number Diff line change @@ -451,7 +451,7 @@ private void handleMutability(Property property) {
451
451
452
452
private void handleOptional (Property property ) {
453
453
if ( this .property != null ) {
454
- property .setOptional ( !isId && isOptional ( this .property ) );
454
+ property .setOptional ( !isId && isOptional ( this .property , this . holder ) );
455
455
if ( property .isOptional () ) {
456
456
final OptionalDeterminationSecondPass secondPass = persistentClasses -> {
457
457
// Defer determining whether a property and its columns are nullable,
@@ -1200,10 +1200,12 @@ private static boolean isExplicitlyOptional(XProperty property) {
1200
1200
* Should this property be considered optional, taking into
1201
1201
* account whether it is primitive?
1202
1202
*/
1203
- private static boolean isOptional (XProperty property ) {
1203
+ public static boolean isOptional (XProperty property , PropertyHolder propertyHolder ) {
1204
1204
return property .isAnnotationPresent ( Basic .class )
1205
1205
? property .getAnnotation ( Basic .class ).optional ()
1206
- : property .isArray () || !property .getClassOrElementClass ().isPrimitive ();
1206
+ : property .isArray ()
1207
+ || propertyHolder != null && propertyHolder .isComponent ()
1208
+ || !property .getClassOrElementClass ().isPrimitive ();
1207
1209
}
1208
1210
1209
1211
private static boolean isLazy (XProperty property ) {
Original file line number Diff line number Diff line change @@ -533,7 +533,7 @@ public Object replace(
533
533
Object owner ,
534
534
Map <Object , Object > copyCache ) {
535
535
536
- if ( original == null && target == null ) {
536
+ if ( original == null ) {
537
537
return null ;
538
538
}
539
539
if ( compositeUserType != null ) {
@@ -570,7 +570,7 @@ public Object replace(
570
570
Map <Object , Object > copyCache ,
571
571
ForeignKeyDirection foreignKeyDirection ) {
572
572
573
- if ( original == null && target == null ) {
573
+ if ( original == null ) {
574
574
return null ;
575
575
}
576
576
if ( compositeUserType != null ) {
You can’t perform that action at this time.
0 commit comments