@@ -501,33 +501,30 @@ private <K> K readEntity(RS rs, MappingContext<K> ctx, @Nullable Object parent,
501
501
args [i ] = parent ;
502
502
} else {
503
503
MappingContext <K > joinCtx = ctx .join (fetchJoinPaths , entityAssociation );
504
- // if join path is null means entity is not joined and we should not try to read it
505
- if (joinCtx .jp != null ) {
506
- Object resolvedId = null ;
507
- if (!entityAssociation .isForeignKey () && !entityAssociation .isSingleEnded ()) {
508
- resolvedId = readEntityId (rs , ctx .path (entityAssociation ));
504
+ Object resolvedId = null ;
505
+ if (!entityAssociation .isForeignKey () && !entityAssociation .isSingleEnded ()) {
506
+ resolvedId = readEntityId (rs , ctx .path (entityAssociation ));
507
+ }
508
+ if (kind .isSingleEnded ()) {
509
+ if (joinCtx .jp == null || resolvedId == null && !entityAssociation .isForeignKey () && !entityAssociation .isSingleEnded ()) {
510
+ args [i ] = buildIdOnlyEntity (rs , ctx .path (entityAssociation ), resolvedId );
511
+ } else {
512
+ args [i ] = readEntity (rs , joinCtx , null , resolvedId );
509
513
}
510
- if (kind .isSingleEnded ()) {
511
- if (joinCtx .jp == null || resolvedId == null && !entityAssociation .isForeignKey () && !entityAssociation .isSingleEnded ()) {
512
- args [i ] = buildIdOnlyEntity (rs , ctx .path (entityAssociation ), resolvedId );
513
- } else {
514
- args [i ] = readEntity (rs , joinCtx , null , resolvedId );
514
+ } else if (entityAssociation .getProperty ().isReadOnly ()) {
515
+ // For constructor-only properties (records) always set empty collection and replace later
516
+ args [i ] = resultReader .convertRequired (new ArrayList <>(0 ), entityAssociation .getProperty ().getType ());
517
+ if (joinCtx .jp != null ) {
518
+ MappingContext <K > associatedCtx = joinCtx .copy ();
519
+ if (resolvedId == null ) {
520
+ resolvedId = readEntityId (rs , associatedCtx );
521
+ }
522
+ Object associatedEntity = null ;
523
+ if (resolvedId != null || entityAssociation .isForeignKey () || entityAssociation .isSingleEnded ()) {
524
+ associatedEntity = readEntity (rs , associatedCtx , null , resolvedId );
515
525
}
516
- } else if (entityAssociation .getProperty ().isReadOnly ()) {
517
- // For constructor-only properties (records) always set empty collection and replace later
518
- args [i ] = resultReader .convertRequired (new ArrayList <>(0 ), entityAssociation .getProperty ().getType ());
519
- if (joinCtx .jp != null ) {
520
- MappingContext <K > associatedCtx = joinCtx .copy ();
521
- if (resolvedId == null ) {
522
- resolvedId = readEntityId (rs , associatedCtx );
523
- }
524
- Object associatedEntity = null ;
525
- if (resolvedId != null || entityAssociation .isForeignKey ()) {
526
- associatedEntity = readEntity (rs , associatedCtx , null , resolvedId );
527
- }
528
- if (associatedEntity != null ) {
529
- joinCtx .associate (associatedCtx , resolvedId , associatedEntity );
530
- }
526
+ if (associatedEntity != null ) {
527
+ joinCtx .associate (associatedCtx , resolvedId , associatedEntity );
531
528
}
532
529
}
533
530
}
0 commit comments