@@ -547,7 +547,6 @@ public boolean containsPossibleCircles(Predicate<PropertyFilter.RelaxedPropertyP
547
547
private boolean calculatePossibleCircles (Predicate <PropertyFilter .RelaxedPropertyPath > includeField ) {
548
548
Collection <RelationshipDescription > relationships = new HashSet <>(getRelationshipsInHierarchy (includeField ));
549
549
550
- Set <NodeDescription <?>> visitedNodes = new HashSet <>();
551
550
for (RelationshipDescription relationship : relationships ) {
552
551
PropertyFilter .RelaxedPropertyPath relaxedPropertyPath = PropertyFilter .RelaxedPropertyPath .withRootType (this .getUnderlyingClass ());
553
552
if (!filterProperties (includeField , relationship , relaxedPropertyPath )) {
@@ -556,13 +555,14 @@ private boolean calculatePossibleCircles(Predicate<PropertyFilter.RelaxedPropert
556
555
// We don't look at the direction because we need to look for cycles based on the modelled relationship
557
556
// direction instead of the "real graph" directions
558
557
NodeDescription <?> targetNode = relationship .getTarget ();
559
- if (visitedNodes . contains (targetNode )) {
558
+ if (this . equals (targetNode )) {
560
559
return true ;
561
560
}
562
- visitedNodes .add (targetNode );
563
561
String relationshipPropertiesPrefix = relationship .hasRelationshipProperties () ? "." + ((Neo4jPersistentEntity <?>) relationship .getRelationshipPropertiesEntity ())
564
562
.getPersistentProperty (TargetNode .class ).getFieldName () : "" ;
565
- if (calculatePossibleCircles (targetNode , new HashSet <>(visitedNodes ), includeField , relaxedPropertyPath .append (relationship .getFieldName () + relationshipPropertiesPrefix ))) {
563
+
564
+ Set <NodeDescription <?>> visitedNodes = new HashSet <>(Collections .singletonList (targetNode ));
565
+ if (calculatePossibleCircles (targetNode , visitedNodes , includeField , relaxedPropertyPath .append (relationship .getFieldName () + relationshipPropertiesPrefix ))) {
566
566
return true ;
567
567
}
568
568
}
@@ -578,7 +578,8 @@ private boolean calculatePossibleCircles(NodeDescription<?> nodeDescription, Set
578
578
return true ;
579
579
}
580
580
visitedNodes .add (targetNode );
581
- if (calculatePossibleCircles (targetNode , new HashSet <>(visitedNodes ), includeField , path .append (relationship .getFieldName ()))) {
581
+ Set <NodeDescription <?>> branchedVisitedNodes = new HashSet <>(visitedNodes );
582
+ if (calculatePossibleCircles (targetNode , branchedVisitedNodes , includeField , path .append (relationship .getFieldName ()))) {
582
583
return true ;
583
584
}
584
585
}
0 commit comments