@@ -264,10 +264,10 @@ private static MapAccessor mergeRootNodeWithRecord(Node node, MapAccessor record
264
264
private <ET > ET map (MapAccessor queryResult , MapAccessor allValues , Neo4jPersistentEntity <ET > nodeDescription ) {
265
265
Collection <Relationship > relationshipsFromResult = extractRelationships (allValues );
266
266
Collection <Node > nodesFromResult = extractNodes (allValues );
267
- return map (queryResult , nodeDescription , null , null , relationshipsFromResult , nodesFromResult );
267
+ return map (queryResult , nodeDescription , nodeDescription , null , null , relationshipsFromResult , nodesFromResult );
268
268
}
269
269
270
- private <ET > ET map (MapAccessor queryResult , Neo4jPersistentEntity <ET > nodeDescription ,
270
+ private <ET > ET map (MapAccessor queryResult , Neo4jPersistentEntity <ET > nodeDescription , NodeDescription <?> genericTargetNodeDescription ,
271
271
@ Nullable Object lastMappedEntity , @ Nullable RelationshipDescription relationshipDescription , Collection <Relationship > relationshipsFromResult , Collection <Node > nodesFromResult ) {
272
272
273
273
// 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
295
295
Neo4jPersistentEntity <ET > concreteNodeDescription = (Neo4jPersistentEntity <ET >) nodeDescriptionAndLabels
296
296
.getNodeDescription ();
297
297
298
- ET instance = instantiate (concreteNodeDescription , queryResult ,
298
+ ET instance = instantiate (concreteNodeDescription , genericTargetNodeDescription , queryResult ,
299
299
nodeDescriptionAndLabels .getDynamicLabels (), lastMappedEntity , relationshipsFromResult , nodesFromResult );
300
300
301
301
knownObjects .removeFromInCreation (internalId );
@@ -416,7 +416,7 @@ private boolean containsOnePlainNode(MapAccessor queryResult) {
416
416
.filter (value -> value .hasType (nodeType )).count () == 1L ;
417
417
}
418
418
419
- private <ET > ET instantiate (Neo4jPersistentEntity <ET > nodeDescription , MapAccessor values ,
419
+ private <ET > ET instantiate (Neo4jPersistentEntity <ET > nodeDescription , NodeDescription <?> genericNodeDescription , MapAccessor values ,
420
420
Collection <String > surplusLabels , @ Nullable Object lastMappedEntity ,
421
421
Collection <Relationship > relationshipsFromResult , Collection <Node > nodesFromResult ) {
422
422
@@ -437,12 +437,12 @@ public <T> T getParameterValue(Parameter<T, Neo4jPersistentProperty> parameter)
437
437
// If we cannot find any value it does not mean that there isn't any.
438
438
// The result set might contain associations not named CONCRETE_TYPE_TARGET but ABSTRACT_TYPE_TARGET.
439
439
// 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 )
441
441
.orElseGet (() -> {
442
442
NodeDescription <?> parentNodeDescription = nodeDescription .getParentNodeDescription ();
443
443
T resultValue = null ;
444
444
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 );
446
446
if (value .isPresent ()) {
447
447
resultValue = (T ) value .get ();
448
448
break ;
@@ -535,7 +535,7 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
535
535
&& propertyValueNotNull ;
536
536
537
537
if (populatedCollection ) {
538
- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , relationshipsFromResult , nodesFromResult , false )
538
+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , baseDescription , relationshipsFromResult , nodesFromResult , false )
539
539
.ifPresent (value -> {
540
540
Collection <?> providedCollection = (Collection <?>) value ;
541
541
Collection <?> existingValue = (Collection <?>) propertyValue ;
@@ -558,7 +558,7 @@ private AssociationHandler<Neo4jPersistentProperty> populateFrom(MapAccessor que
558
558
return ;
559
559
}
560
560
561
- createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , relationshipsFromResult , nodesFromResult )
561
+ createInstanceOfRelationships (persistentProperty , queryResult , (RelationshipDescription ) association , baseDescription , baseDescription , relationshipsFromResult , nodesFromResult )
562
562
.ifPresent (value -> propertyAccessor .setProperty (persistentProperty , value ));
563
563
};
564
564
}
@@ -582,13 +582,13 @@ private void mergeCollections(RelationshipDescription relationshipDescription, C
582
582
}
583
583
584
584
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 ,
586
586
Collection <Node > nodesFromResult ) {
587
- return createInstanceOfRelationships (persistentProperty , values , relationshipDescription , baseDescription , relationshipsFromResult , nodesFromResult , true );
587
+ return createInstanceOfRelationships (persistentProperty , values , relationshipDescription , baseDescription , genericNodeDescription , relationshipsFromResult , nodesFromResult , true );
588
588
}
589
589
590
590
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 ,
592
592
Collection <Node > nodesFromResult , boolean fetchMore ) {
593
593
594
594
String typeOfRelationship = relationshipDescription .getType ();
@@ -622,7 +622,7 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
622
622
mappedObjectHandler = (type , mappedObject ) -> value .add (mappedObject );
623
623
}
624
624
625
- String collectionName = relationshipDescription .generateRelatedNodesCollectionName (baseDescription );
625
+ String collectionName = relationshipDescription .generateRelatedNodesCollectionName (genericNodeDescription );
626
626
627
627
Value list = values .get (collectionName );
628
628
@@ -670,23 +670,24 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
670
670
if (fetchMore ) {
671
671
mappedObject = sourceNodeId != null && sourceNodeId .equals (targetNodeId )
672
672
? knownObjects .getObject ("N" + sourceNodeId )
673
- : map (possibleValueNode , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
673
+ : map (possibleValueNode , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
674
674
} else {
675
675
Object objectFromStore = knownObjects .getObject ("N" + targetNodeId );
676
676
mappedObject = objectFromStore != null
677
677
? objectFromStore
678
- : map (possibleValueNode , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
678
+ : map (possibleValueNode , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
679
679
}
680
680
681
681
if (relationshipDescription .hasRelationshipProperties ()) {
682
682
Object relationshipProperties ;
683
+ Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
683
684
if (fetchMore ) {
684
- relationshipProperties = map (possibleRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
685
+ relationshipProperties = map (possibleRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
685
686
} else {
686
687
Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (possibleRelationship , relationshipDescription .getDirection ().name ()));
687
688
relationshipProperties = objectFromStore != null
688
689
? objectFromStore
689
- : map (possibleRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
690
+ : map (possibleRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , mappedObject , relationshipDescription , relationshipsFromResult , nodesFromResult );
690
691
}
691
692
relationshipsAndProperties .add (relationshipProperties );
692
693
mappedObjectHandler .accept (possibleRelationship .type (), relationshipProperties );
@@ -706,29 +707,30 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
706
707
707
708
Object valueEntry ;
708
709
if (fetchMore ) {
709
- valueEntry = map (relatedEntity , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
710
+ valueEntry = map (relatedEntity , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
710
711
} else {
711
712
Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (relatedEntity , null ));
712
713
valueEntry = objectFromStore != null
713
714
? objectFromStore
714
- : map (relatedEntity , concreteTargetNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
715
+ : map (relatedEntity , concreteTargetNodeDescription , genericNodeDescription , null , null , relationshipsFromResult , nodesFromResult );
715
716
}
716
717
717
718
if (relationshipDescription .hasRelationshipProperties ()) {
718
- String sourceLabel = relationshipDescription .getSource ().getMostAbstractParentLabel (baseDescription );
719
+ String sourceLabel = relationshipDescription .getSource ().getMostAbstractParentLabel (genericNodeDescription );
719
720
String relationshipSymbolicName = sourceLabel
720
721
+ RelationshipDescription .NAME_OF_RELATIONSHIP + targetLabel ;
721
722
Relationship relatedEntityRelationship = relatedEntity .get (relationshipSymbolicName )
722
723
.asRelationship ();
723
724
724
725
Object relationshipProperties ;
726
+ Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
725
727
if (fetchMore ) {
726
- relationshipProperties = map (relatedEntityRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
728
+ relationshipProperties = map (relatedEntityRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
727
729
} else {
728
730
Object objectFromStore = knownObjects .getObject (IdentitySupport .getInternalId (relatedEntityRelationship , relationshipDescription .getDirection ().name ()));
729
731
relationshipProperties = objectFromStore != null
730
732
? objectFromStore
731
- : map (relatedEntityRelationship , ( Neo4jPersistentEntity <?>) relationshipDescription . getRelationshipPropertiesEntity () , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
733
+ : map (relatedEntityRelationship , relationshipPropertiesEntity , relationshipPropertiesEntity , valueEntry , relationshipDescription , relationshipsFromResult , nodesFromResult );
732
734
}
733
735
734
736
relationshipsAndProperties .add (relationshipProperties );
0 commit comments