@@ -264,10 +264,10 @@ private static MapAccessor mergeRootNodeWithRecord(Node node, MapAccessor record
264264 private <ET > ET map (MapAccessor queryResult , MapAccessor allValues , Neo4jPersistentEntity <ET > nodeDescription ) {
265265 Collection <Relationship > relationshipsFromResult = extractRelationships (allValues );
266266 Collection <Node > nodesFromResult = extractNodes (allValues );
267- return map (queryResult , nodeDescription , null , null , relationshipsFromResult , nodesFromResult );
267+ return map (queryResult , nodeDescription , nodeDescription , null , null , relationshipsFromResult , nodesFromResult );
268268 }
269269
270- private <ET > ET map (MapAccessor queryResult , Neo4jPersistentEntity <ET > nodeDescription ,
270+ private <ET > ET map (MapAccessor queryResult , Neo4jPersistentEntity <ET > nodeDescription , NodeDescription <?> genericTargetNodeDescription ,
271271 @ Nullable Object lastMappedEntity , @ Nullable RelationshipDescription relationshipDescription , Collection <Relationship > relationshipsFromResult , Collection <Node > nodesFromResult ) {
272272
273273 // prior to SDN 7 local `getInternalId` didn't check relationships, so in that case, they have never been a known
@@ -295,7 +295,7 @@ private <ET> ET map(MapAccessor queryResult, Neo4jPersistentEntity<ET> nodeDescr
295295 Neo4jPersistentEntity <ET > concreteNodeDescription = (Neo4jPersistentEntity <ET >) nodeDescriptionAndLabels
296296 .getNodeDescription ();
297297
298- ET instance = instantiate (concreteNodeDescription , queryResult ,
298+ ET instance = instantiate (concreteNodeDescription , genericTargetNodeDescription , queryResult ,
299299 nodeDescriptionAndLabels .getDynamicLabels (), lastMappedEntity , relationshipsFromResult , nodesFromResult );
300300
301301 knownObjects .removeFromInCreation (internalId );
@@ -416,7 +416,7 @@ private boolean containsOnePlainNode(MapAccessor queryResult) {
416416 .filter (value -> value .hasType (nodeType )).count () == 1L ;
417417 }
418418
419- private <ET > ET instantiate (Neo4jPersistentEntity <ET > nodeDescription , MapAccessor values ,
419+ private <ET > ET instantiate (Neo4jPersistentEntity <ET > nodeDescription , NodeDescription <?> genericNodeDescription , MapAccessor values ,
420420 Collection <String > surplusLabels , @ Nullable Object lastMappedEntity ,
421421 Collection <Relationship > relationshipsFromResult , Collection <Node > nodesFromResult ) {
422422
@@ -437,12 +437,12 @@ public <T> T getParameterValue(Parameter<T, Neo4jPersistentProperty> parameter)
437437 // If we cannot find any value it does not mean that there isn't any.
438438 // The result set might contain associations not named CONCRETE_TYPE_TARGET but ABSTRACT_TYPE_TARGET.
439439 // For this we bubble up the hierarchy of NodeDescriptions.
440- result = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , nodeDescription , relationshipsFromResult , nodesFromResult )
440+ result = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , nodeDescription , genericNodeDescription , relationshipsFromResult , nodesFromResult )
441441 .orElseGet (() -> {
442442 NodeDescription <?> parentNodeDescription = nodeDescription .getParentNodeDescription ();
443443 T resultValue = null ;
444444 while (parentNodeDescription != null ) {
445- Optional <Object > value = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , parentNodeDescription , relationshipsFromResult , nodesFromResult );
445+ Optional <Object > value = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , parentNodeDescription , parentNodeDescription , relationshipsFromResult , nodesFromResult );
446446 if (value .isPresent ()) {
447447 resultValue = (T ) value .get ();
448448 break ;
@@ -535,7 +535,7 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
535535 && propertyValueNotNull ;
536536
537537 if (populatedCollection ) {
538- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , relationshipsFromResult , nodesFromResult , false )
538+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , baseDescription , relationshipsFromResult , nodesFromResult , false )
539539 .ifPresent (value -> {
540540 Collection <?> providedCollection = (Collection <?>) value ;
541541 Collection <?> existingValue = (Collection <?>) propertyValue ;
@@ -558,7 +558,7 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
558558 return ;
559559 }
560560
561- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , relationshipsFromResult , nodesFromResult )
561+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , baseDescription , relationshipsFromResult , nodesFromResult )
562562 .ifPresent (value -> propertyAccessor .setProperty (persistentProperty , value ));
563563 };
564564 }
@@ -582,13 +582,13 @@ private void mergeCollections(RelationshipDescription relationshipDescription, C
582582 }
583583
584584 private Optional <Object > createInstanceOfRelationships (Neo4jPersistentProperty persistentProperty , MapAccessor values ,
585- RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , Collection <Relationship > relationshipsFromResult ,
585+ RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , NodeDescription <?> genericNodeDescription , Collection <Relationship > relationshipsFromResult ,
586586 Collection <Node > nodesFromResult ) {
587- return createInstanceOfRelationships (persistentProperty , values , relationshipDescription , baseDescription , relationshipsFromResult , nodesFromResult , true );
587+ return createInstanceOfRelationships (persistentProperty , values , relationshipDescription , baseDescription , genericNodeDescription , relationshipsFromResult , nodesFromResult , true );
588588 }
589589
590590 private Optional <Object > createInstanceOfRelationships (Neo4jPersistentProperty persistentProperty , MapAccessor values ,
591- RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , Collection <Relationship > relationshipsFromResult ,
591+ RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , NodeDescription <?> genericNodeDescription , Collection <Relationship > relationshipsFromResult ,
592592 Collection <Node > nodesFromResult , boolean fetchMore ) {
593593
594594 String typeOfRelationship = relationshipDescription .getType ();
@@ -622,7 +622,7 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
622622 mappedObjectHandler = (type , mappedObject ) -> value .add (mappedObject );
623623 }
624624
625- String collectionName = relationshipDescription .generateRelatedNodesCollectionName (baseDescription );
625+ String collectionName = relationshipDescription .generateRelatedNodesCollectionName (genericNodeDescription );
626626
627627 Value list = values .get (collectionName );
628628
@@ -670,23 +670,24 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
670670 if (fetchMore ) {
671671 mappedObject = sourceNodeId != null && sourceNodeId .equals (targetNodeId )
672672 ? knownObjects .getObject ("N" + sourceNodeId )
673- : map (possibleValueNode , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
673+ : map (possibleValueNode , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
674674 } else {
675675 Object objectFromStore = knownObjects .getObject ("N" + targetNodeId );
676676 mappedObject = objectFromStore != null
677677 ? objectFromStore
678- : map (possibleValueNode , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
678+ : map (possibleValueNode , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
679679 }
680680
681681 if (relationshipDescription .hasRelationshipProperties ()) {
682682 Object relationshipProperties ;
683+ Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
683684 if (fetchMore ) {
684- relationshipProperties = map (possibleRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
685+ relationshipProperties = map (possibleRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
685686 } else {
686687 Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (possibleRelationship , relationshipDescription .getDirection ().name ()));
687688 relationshipProperties = objectFromStore != null
688689 ? objectFromStore
689- : map (possibleRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
690+ : map (possibleRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
690691 }
691692 relationshipsAndProperties .add (relationshipProperties );
692693 mappedObjectHandler .accept (possibleRelationship .type (), relationshipProperties );
@@ -706,29 +707,30 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
706707
707708 Object valueEntry ;
708709 if (fetchMore ) {
709- valueEntry = map (relatedEntity , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
710+ valueEntry = map (relatedEntity , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
710711 } else {
711712 Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (relatedEntity , null ));
712713 valueEntry = objectFromStore != null
713714 ? objectFromStore
714- : map (relatedEntity , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
715+ : map (relatedEntity , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
715716 }
716717
717718 if (relationshipDescription .hasRelationshipProperties ()) {
718- String sourceLabel = relationshipDescription .getSource ().getMostAbstractParentLabel (baseDescription );
719+ String sourceLabel = relationshipDescription .getSource ().getMostAbstractParentLabel (genericNodeDescription );
719720 String relationshipSymbolicName = sourceLabel
720721 + RelationshipDescription .NAME_OF_RELATIONSHIP + targetLabel ;
721722 Relationship relatedEntityRelationship = relatedEntity .get (relationshipSymbolicName )
722723 .asRelationship ();
723724
724725 Object relationshipProperties ;
726+ Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
725727 if (fetchMore ) {
726- relationshipProperties = map (relatedEntityRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
728+ relationshipProperties = map (relatedEntityRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
727729 } else {
728730 Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (relatedEntityRelationship , relationshipDescription .getDirection ().name ()));
729731 relationshipProperties = objectFromStore != null
730732 ? objectFromStore
731- : map (relatedEntityRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
733+ : map (relatedEntityRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
732734 }
733735
734736 relationshipsAndProperties .add (relationshipProperties );
0 commit comments