@@ -307,7 +307,7 @@ && equal( join.getKey(), manyToOne ) ) {
307
307
this .hasJoinTable = hasJoinTable ;
308
308
}
309
309
else {
310
- this .hasJoinTable = false ;
310
+ this .hasJoinTable = manyToOne . hasJoinTable () ;
311
311
bidirectionalAttributeName = findBidirectionalOneToManyAttributeName (
312
312
propertyPath ,
313
313
declaringType ,
@@ -361,7 +361,7 @@ && equal( join.getKey(), manyToOne ) ) {
361
361
}
362
362
}
363
363
isOptional = manyToOne .isIgnoreNotFound ();
364
- isInternalLoadNullable = ( isNullable && bootValue .isForeignKeyEnabled () ) || hasNotFoundAction ();
364
+ isInternalLoadNullable = isNullable && bootValue .isForeignKeyEnabled () || hasNotFoundAction ();
365
365
}
366
366
else {
367
367
assert bootValue instanceof OneToOne ;
@@ -412,12 +412,10 @@ the navigable path is NavigablePath(Card.fields.{element}.{id}.card) and it does
412
412
so in order to recognize the bidirectionality the "primaryKey." is removed from the otherSidePropertyName value.
413
413
*/
414
414
final OneToOne oneToOne = (OneToOne ) bootValue ;
415
- if ( oneToOne .getMappedByProperty () == null ) {
416
- this .bidirectionalAttributePath = SelectablePath .parse ( referencedPropertyName );
417
- }
418
- else {
419
- this .bidirectionalAttributePath = SelectablePath .parse ( oneToOne .getMappedByProperty () );
420
- }
415
+ this .bidirectionalAttributePath =
416
+ oneToOne .getMappedByProperty () == null
417
+ ? SelectablePath .parse ( referencedPropertyName )
418
+ : SelectablePath .parse ( oneToOne .getMappedByProperty () );
421
419
notFoundAction = null ;
422
420
isKeyTableNullable = isNullable ();
423
421
isOptional = !bootValue .isConstrained ();
@@ -628,10 +626,9 @@ else if ( value instanceof OneToOne oneToOne ) {
628
626
return null ;
629
627
}
630
628
631
- private static FetchTiming adjustFetchTiming (
632
- FetchTiming mappedFetchTiming ,
633
- ToOne bootValue ) {
634
- return bootValue instanceof ManyToOne manyToOne && manyToOne .getNotFoundAction () != null
629
+ private static FetchTiming adjustFetchTiming (FetchTiming mappedFetchTiming , ToOne bootValue ) {
630
+ return bootValue instanceof ManyToOne manyToOne
631
+ && manyToOne .getNotFoundAction () != null
635
632
? FetchTiming .IMMEDIATE
636
633
: mappedFetchTiming ;
637
634
}
@@ -641,9 +638,8 @@ private static TableGroupProducer resolveDeclaringTableGroupProducer(EntityPersi
641
638
NavigableRole parentRole = navigableRole .getParent ();
642
639
String collectionRole = null ;
643
640
do {
644
- final CollectionPart .Nature nature = CollectionPart .Nature .fromNameExact (
645
- parentRole .getLocalName ()
646
- );
641
+ final CollectionPart .Nature nature =
642
+ CollectionPart .Nature .fromNameExact ( parentRole .getLocalName () );
647
643
if (nature != null ) {
648
644
collectionRole = parentRole .getParent ().getFullPath ();
649
645
break ;
@@ -1175,11 +1171,10 @@ class Mother {
1175
1171
// If the parent is null, this is a simple collection fetch of a root, in which case the types must match
1176
1172
if ( parentPath .getParent () == null ) {
1177
1173
final String entityName = entityMappingType .getPartName ();
1178
- return parentPath .getFullPath ().startsWith ( entityName ) && (
1179
- parentPath .getFullPath ().length () == entityName .length ()
1180
- // Ignore a possible alias
1181
- || parentPath .getFullPath ().charAt ( entityName .length () ) == '('
1182
- );
1174
+ return parentPath .getFullPath ().startsWith ( entityName )
1175
+ && ( parentPath .getFullPath ().length () == entityName .length ()
1176
+ // Ignore a possible alias
1177
+ || parentPath .getFullPath ().charAt ( entityName .length () ) == '(' );
1183
1178
}
1184
1179
// If we have a parent, we ensure that the parent is the same as the attribute name
1185
1180
else {
@@ -2109,8 +2104,9 @@ public TableGroupJoin createTableGroupJoin(
2109
2104
// @SQLRestriction should not be applied when joining FK association,
2110
2105
// because that would result in us setting the FK to null when the
2111
2106
// owning entity is updated, that is, to data loss.
2112
- // But we'll let it apply on the TARGET side of a @OneToOne
2113
- if ( sideNature == ForeignKeyDescriptor .Nature .TARGET ) {
2107
+ // But we let it apply on the TARGET side of a @OneToOne, and we apply
2108
+ // it whenever there is a dedicated join table.
2109
+ if ( hasJoinTable || sideNature == ForeignKeyDescriptor .Nature .TARGET ) {
2114
2110
associatedEntityMappingType .applyWhereRestrictions (
2115
2111
join ::applyPredicate ,
2116
2112
tableGroup ,
0 commit comments