@@ -429,7 +429,23 @@ public <T> T getParameterValue(PreferredConstructor.Parameter<T, Neo4jPersistent
429
429
String propertyFieldName = matchingProperty .getFieldName ();
430
430
return r .getFieldName ().equals (propertyFieldName );
431
431
}).findFirst ().get ();
432
- result = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , relationshipsFromResult , nodesFromResult ).orElse (null );
432
+ // If we cannot find any value it does not mean that there isn't any.
433
+ // The result set might contain associations not named CONCRETE_TYPE_TARGET but ABSTRACT_TYPE_TARGET.
434
+ // For this we bubble up the hierarchy of NodeDescriptions.
435
+ result = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , relationshipsFromResult , nodesFromResult , null )
436
+ .orElseGet (() -> {
437
+ NodeDescription <?> parentNodeDescription = nodeDescription .getParentNodeDescription ();
438
+ T resultValue = null ;
439
+ while (parentNodeDescription != null ) {
440
+ Optional <Object > value = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , relationshipsFromResult , nodesFromResult , parentNodeDescription );
441
+ if (value .isPresent ()) {
442
+ resultValue = (T ) value .get ();
443
+ break ;
444
+ }
445
+ parentNodeDescription = parentNodeDescription .getParentNodeDescription ();
446
+ }
447
+ return resultValue ;
448
+ });
433
449
} else if (matchingProperty .isDynamicLabels ()) {
434
450
result = createDynamicLabelsProperty (matchingProperty .getTypeInformation (), surplusLabels );
435
451
} else if (matchingProperty .isEntityWithRelationshipProperties ()) {
@@ -518,13 +534,14 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
518
534
}
519
535
}
520
536
521
- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , relationshipsFromResult , nodesFromResult )
537
+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , relationshipsFromResult , nodesFromResult , null )
522
538
.ifPresent (value -> propertyAccessor .setProperty (persistentProperty , value ));
523
539
};
524
540
}
525
541
526
542
private Optional <Object > createInstanceOfRelationships (Neo4jPersistentProperty persistentProperty , MapAccessor values ,
527
- RelationshipDescription relationshipDescription , Collection <Relationship > relationshipsFromResult , Collection <Node > nodesFromResult ) {
543
+ RelationshipDescription relationshipDescription , Collection <Relationship > relationshipsFromResult ,
544
+ Collection <Node > nodesFromResult , @ Nullable NodeDescription <?> nodeDescription ) {
528
545
529
546
String typeOfRelationship = relationshipDescription .getType ();
530
547
String sourceLabel = relationshipDescription .getSource ().getPrimaryLabel ();
@@ -558,8 +575,13 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
558
575
mappedObjectHandler = (type , mappedObject ) -> value .add (mappedObject );
559
576
}
560
577
561
- String collectionName =
562
- relationshipDescription .generateRelatedNodesCollectionName (relationshipDescription .getSource ());
578
+ // Generate name driven by the (nullable) NodeDescription of necessary,
579
+ // because it might contain associations not named CONCRETE_TYPE_TARGET but ABSTRACT_TYPE_TARGET
580
+ String collectionName = relationshipDescription .generateRelatedNodesCollectionName (
581
+ nodeDescription != null
582
+ ? nodeDescription
583
+ : relationshipDescription .getSource ()
584
+ );
563
585
564
586
Value list = values .get (collectionName );
565
587
@@ -672,7 +694,9 @@ private Collection<Node> extractNodes(MapAccessor allValues) {
672
694
return allNodesInResult ;
673
695
}
674
696
675
- private Collection <Relationship > extractMatchingRelationships (Collection <Relationship > relationshipsFromResult , RelationshipDescription relationshipDescription , String typeOfRelationship , Predicate <Relationship > relationshipPredicate ) {
697
+ private Collection <Relationship > extractMatchingRelationships (Collection <Relationship > relationshipsFromResult ,
698
+ RelationshipDescription relationshipDescription , String typeOfRelationship ,
699
+ Predicate <Relationship > relationshipPredicate ) {
676
700
677
701
Predicate <Relationship > onlyWithMatchingType = r -> r .type ().equals (typeOfRelationship ) || relationshipDescription .isDynamic ();
678
702
return relationshipsFromResult .stream ()
0 commit comments