@@ -429,7 +429,23 @@ public <T> T getParameterValue(PreferredConstructor.Parameter<T, Neo4jPersistent
429429 String propertyFieldName = matchingProperty .getFieldName ();
430430 return r .getFieldName ().equals (propertyFieldName );
431431 }).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+ });
433449 } else if (matchingProperty .isDynamicLabels ()) {
434450 result = createDynamicLabelsProperty (matchingProperty .getTypeInformation (), surplusLabels );
435451 } else if (matchingProperty .isEntityWithRelationshipProperties ()) {
@@ -518,13 +534,14 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
518534 }
519535 }
520536
521- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , relationshipsFromResult , nodesFromResult )
537+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , relationshipsFromResult , nodesFromResult , null )
522538 .ifPresent (value -> propertyAccessor .setProperty (persistentProperty , value ));
523539 };
524540 }
525541
526542 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 ) {
528545
529546 String typeOfRelationship = relationshipDescription .getType ();
530547 String sourceLabel = relationshipDescription .getSource ().getPrimaryLabel ();
@@ -558,8 +575,13 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
558575 mappedObjectHandler = (type , mappedObject ) -> value .add (mappedObject );
559576 }
560577
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+ );
563585
564586 Value list = values .get (collectionName );
565587
@@ -672,7 +694,9 @@ private Collection<Node> extractNodes(MapAccessor allValues) {
672694 return allNodesInResult ;
673695 }
674696
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 ) {
676700
677701 Predicate <Relationship > onlyWithMatchingType = r -> r .type ().equals (typeOfRelationship ) || relationshipDescription .isDynamic ();
678702 return relationshipsFromResult .stream ()
0 commit comments