Skip to content

Commit 7cbf8c6

Browse files
committed
GH-2317 - Some more tweaks.
1 parent c9f0d46 commit 7cbf8c6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntity.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ public boolean containsPossibleCircles(Predicate<PropertyFilter.RelaxedPropertyP
547547
private boolean calculatePossibleCircles(Predicate<PropertyFilter.RelaxedPropertyPath> includeField) {
548548
Collection<RelationshipDescription> relationships = new HashSet<>(getRelationshipsInHierarchy(includeField));
549549

550-
Set<NodeDescription<?>> visitedNodes = new HashSet<>();
551550
for (RelationshipDescription relationship : relationships) {
552551
PropertyFilter.RelaxedPropertyPath relaxedPropertyPath = PropertyFilter.RelaxedPropertyPath.withRootType(this.getUnderlyingClass());
553552
if (!filterProperties(includeField, relationship, relaxedPropertyPath)) {
@@ -556,13 +555,14 @@ private boolean calculatePossibleCircles(Predicate<PropertyFilter.RelaxedPropert
556555
// We don't look at the direction because we need to look for cycles based on the modelled relationship
557556
// direction instead of the "real graph" directions
558557
NodeDescription<?> targetNode = relationship.getTarget();
559-
if (visitedNodes.contains(targetNode)) {
558+
if (this.equals(targetNode)) {
560559
return true;
561560
}
562-
visitedNodes.add(targetNode);
563561
String relationshipPropertiesPrefix = relationship.hasRelationshipProperties() ? "." + ((Neo4jPersistentEntity<?>) relationship.getRelationshipPropertiesEntity())
564562
.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))) {
566566
return true;
567567
}
568568
}
@@ -578,7 +578,8 @@ private boolean calculatePossibleCircles(NodeDescription<?> nodeDescription, Set
578578
return true;
579579
}
580580
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()))) {
582583
return true;
583584
}
584585
}

0 commit comments

Comments
 (0)