@@ -299,10 +299,10 @@ private static MapAccessor mergeRootNodeWithRecord(Node node, MapAccessor record
299
299
private <ET > ET map (MapAccessor queryResult , MapAccessor allValues , Neo4jPersistentEntity <ET > nodeDescription ) {
300
300
Collection <Relationship > relationshipsFromResult = extractRelationships (allValues );
301
301
Collection <Node > nodesFromResult = extractNodes (allValues );
302
- return map (queryResult , nodeDescription , null , null , relationshipsFromResult , nodesFromResult );
302
+ return map (queryResult , nodeDescription , nodeDescription , null , null , relationshipsFromResult , nodesFromResult );
303
303
}
304
304
305
- private <ET > ET map (MapAccessor queryResult , Neo4jPersistentEntity <ET > nodeDescription ,
305
+ private <ET > ET map (MapAccessor queryResult , Neo4jPersistentEntity <ET > nodeDescription , NodeDescription <?> genericTargetNodeDescription ,
306
306
@ Nullable Object lastMappedEntity , @ Nullable RelationshipDescription relationshipDescription , Collection <Relationship > relationshipsFromResult , Collection <Node > nodesFromResult ) {
307
307
308
308
// prior to SDN 7 local `getInternalId` didn't check relationships, so in that case, they have never been a known
@@ -330,7 +330,7 @@ private <ET> ET map(MapAccessor queryResult, Neo4jPersistentEntity<ET> nodeDescr
330
330
Neo4jPersistentEntity <ET > concreteNodeDescription = (Neo4jPersistentEntity <ET >) nodeDescriptionAndLabels
331
331
.getNodeDescription ();
332
332
333
- ET instance = instantiate (concreteNodeDescription , queryResult ,
333
+ ET instance = instantiate (concreteNodeDescription , genericTargetNodeDescription , queryResult ,
334
334
nodeDescriptionAndLabels .getDynamicLabels (), lastMappedEntity , relationshipsFromResult , nodesFromResult );
335
335
336
336
knownObjects .removeFromInCreation (internalId );
@@ -451,7 +451,7 @@ private boolean containsOnePlainNode(MapAccessor queryResult) {
451
451
.filter (value -> value .hasType (nodeType )).count () == 1L ;
452
452
}
453
453
454
- private <ET > ET instantiate (Neo4jPersistentEntity <ET > nodeDescription , MapAccessor values ,
454
+ private <ET > ET instantiate (Neo4jPersistentEntity <ET > nodeDescription , NodeDescription <?> genericNodeDescription , MapAccessor values ,
455
455
Collection <String > surplusLabels , @ Nullable Object lastMappedEntity ,
456
456
Collection <Relationship > relationshipsFromResult , Collection <Node > nodesFromResult ) {
457
457
@@ -472,12 +472,12 @@ public <T> T getParameterValue(Parameter<T, Neo4jPersistentProperty> parameter)
472
472
// If we cannot find any value it does not mean that there isn't any.
473
473
// The result set might contain associations not named CONCRETE_TYPE_TARGET but ABSTRACT_TYPE_TARGET.
474
474
// For this we bubble up the hierarchy of NodeDescriptions.
475
- result = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , nodeDescription , relationshipsFromResult , nodesFromResult )
475
+ result = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , nodeDescription , genericNodeDescription , relationshipsFromResult , nodesFromResult )
476
476
.orElseGet (() -> {
477
477
NodeDescription <?> parentNodeDescription = nodeDescription .getParentNodeDescription ();
478
478
T resultValue = null ;
479
479
while (parentNodeDescription != null ) {
480
- Optional <Object > value = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , parentNodeDescription , relationshipsFromResult , nodesFromResult );
480
+ Optional <Object > value = createInstanceOfRelationships (matchingProperty , values , relationshipDescription , parentNodeDescription , parentNodeDescription , relationshipsFromResult , nodesFromResult );
481
481
if (value .isPresent ()) {
482
482
resultValue = (T ) value .get ();
483
483
break ;
@@ -570,7 +570,7 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
570
570
&& propertyValueNotNull ;
571
571
572
572
if (populatedCollection ) {
573
- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , relationshipsFromResult , nodesFromResult , false )
573
+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , baseDescription , relationshipsFromResult , nodesFromResult , false )
574
574
.ifPresent (value -> {
575
575
Collection <?> providedCollection = (Collection <?>) value ;
576
576
Collection <?> existingValue = (Collection <?>) propertyValue ;
@@ -593,7 +593,7 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
593
593
return ;
594
594
}
595
595
596
- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , relationshipsFromResult , nodesFromResult )
596
+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , baseDescription , relationshipsFromResult , nodesFromResult )
597
597
.ifPresent (value -> propertyAccessor .setProperty (persistentProperty , value ));
598
598
};
599
599
}
@@ -617,13 +617,13 @@ private void mergeCollections(RelationshipDescription relationshipDescription, C
617
617
}
618
618
619
619
private Optional <Object > createInstanceOfRelationships (Neo4jPersistentProperty persistentProperty , MapAccessor values ,
620
- RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , Collection <Relationship > relationshipsFromResult ,
620
+ RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , NodeDescription <?> genericNodeDescription , Collection <Relationship > relationshipsFromResult ,
621
621
Collection <Node > nodesFromResult ) {
622
- return createInstanceOfRelationships (persistentProperty , values , relationshipDescription , baseDescription , relationshipsFromResult , nodesFromResult , true );
622
+ return createInstanceOfRelationships (persistentProperty , values , relationshipDescription , baseDescription , genericNodeDescription , relationshipsFromResult , nodesFromResult , true );
623
623
}
624
624
625
625
private Optional <Object > createInstanceOfRelationships (Neo4jPersistentProperty persistentProperty , MapAccessor values ,
626
- RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , Collection <Relationship > relationshipsFromResult ,
626
+ RelationshipDescription relationshipDescription , NodeDescription <?> baseDescription , NodeDescription <?> genericNodeDescription , Collection <Relationship > relationshipsFromResult ,
627
627
Collection <Node > nodesFromResult , boolean fetchMore ) {
628
628
629
629
String typeOfRelationship = relationshipDescription .getType ();
@@ -657,7 +657,7 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
657
657
mappedObjectHandler = (type , mappedObject ) -> value .add (mappedObject );
658
658
}
659
659
660
- String collectionName = relationshipDescription .generateRelatedNodesCollectionName (baseDescription );
660
+ String collectionName = relationshipDescription .generateRelatedNodesCollectionName (genericNodeDescription );
661
661
662
662
Value list = values .get (collectionName );
663
663
@@ -705,23 +705,24 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
705
705
if (fetchMore ) {
706
706
mappedObject = sourceNodeId != null && sourceNodeId .equals (targetNodeId )
707
707
? knownObjects .getObject ("N" + sourceNodeId )
708
- : map (possibleValueNode , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
708
+ : map (possibleValueNode , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
709
709
} else {
710
710
Object objectFromStore = knownObjects .getObject ("N" + targetNodeId );
711
711
mappedObject = objectFromStore != null
712
712
? objectFromStore
713
- : map (possibleValueNode , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
713
+ : map (possibleValueNode , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
714
714
}
715
715
716
716
if (relationshipDescription .hasRelationshipProperties ()) {
717
717
Object relationshipProperties ;
718
+ Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
718
719
if (fetchMore ) {
719
- relationshipProperties = map (possibleRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
720
+ relationshipProperties = map (possibleRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
720
721
} else {
721
722
Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (possibleRelationship , relationshipDescription .getDirection ().name ()));
722
723
relationshipProperties = objectFromStore != null
723
724
? objectFromStore
724
- : map (possibleRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
725
+ : map (possibleRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
725
726
}
726
727
relationshipsAndProperties .add (relationshipProperties );
727
728
mappedObjectHandler .accept (possibleRelationship .type (), relationshipProperties );
@@ -741,29 +742,30 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
741
742
742
743
Object valueEntry ;
743
744
if (fetchMore ) {
744
- valueEntry = map (relatedEntity , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
745
+ valueEntry = map (relatedEntity , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
745
746
} else {
746
747
Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (relatedEntity , null ));
747
748
valueEntry = objectFromStore != null
748
749
? objectFromStore
749
- : map (relatedEntity , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
750
+ : map (relatedEntity , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
750
751
}
751
752
752
753
if (relationshipDescription .hasRelationshipProperties ()) {
753
- String sourceLabel = relationshipDescription .getSource ().getMostAbstractParentLabel (baseDescription );
754
+ String sourceLabel = relationshipDescription .getSource ().getMostAbstractParentLabel (genericNodeDescription );
754
755
String relationshipSymbolicName = sourceLabel
755
756
+ RelationshipDescription .NAME_OF_RELATIONSHIP + targetLabel ;
756
757
Relationship relatedEntityRelationship = relatedEntity .get (relationshipSymbolicName )
757
758
.asRelationship ();
758
759
759
760
Object relationshipProperties ;
761
+ Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
760
762
if (fetchMore ) {
761
- relationshipProperties = map (relatedEntityRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
763
+ relationshipProperties = map (relatedEntityRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
762
764
} else {
763
765
Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (relatedEntityRelationship , relationshipDescription .getDirection ().name ()));
764
766
relationshipProperties = objectFromStore != null
765
767
? objectFromStore
766
- : map (relatedEntityRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
768
+ : map (relatedEntityRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
767
769
}
768
770
769
771
relationshipsAndProperties .add (relationshipProperties );
0 commit comments