@@ -547,34 +547,38 @@ 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 <RelationshipDescription > processedRelationships = new HashSet <>();
550
+ Set <NodeDescription <?>> visitedNodes = new HashSet <>();
551
551
for (RelationshipDescription relationship : relationships ) {
552
552
PropertyFilter .RelaxedPropertyPath relaxedPropertyPath = PropertyFilter .RelaxedPropertyPath .withRootType (this .getUnderlyingClass ());
553
553
if (!filterProperties (includeField , relationship , relaxedPropertyPath )) {
554
554
continue ;
555
555
}
556
- if (processedRelationships .contains (relationship )) {
556
+ // We don't look at the direction because we need to look for cycles based on the modelled relationship
557
+ // direction instead of the "real graph" directions
558
+ NodeDescription <?> targetNode = relationship .getTarget ();
559
+ if (visitedNodes .contains (targetNode )) {
557
560
return true ;
558
561
}
559
- processedRelationships .add (relationship );
562
+ visitedNodes .add (targetNode );
560
563
String relationshipPropertiesPrefix = relationship .hasRelationshipProperties () ? "." + ((Neo4jPersistentEntity <?>) relationship .getRelationshipPropertiesEntity ())
561
564
.getPersistentProperty (TargetNode .class ).getFieldName () : "" ;
562
- if (calculatePossibleCircles (relationship . getTarget (), processedRelationships , includeField , relaxedPropertyPath .append (relationship .getFieldName () + relationshipPropertiesPrefix ))) {
565
+ if (calculatePossibleCircles (targetNode , new HashSet <>( visitedNodes ) , includeField , relaxedPropertyPath .append (relationship .getFieldName () + relationshipPropertiesPrefix ))) {
563
566
return true ;
564
567
}
565
568
}
566
569
return false ;
567
570
}
568
571
569
- private boolean calculatePossibleCircles (NodeDescription <?> nodeDescription , Set <RelationshipDescription > processedRelationships , Predicate <PropertyFilter .RelaxedPropertyPath > includeField , PropertyFilter .RelaxedPropertyPath path ) {
572
+ private boolean calculatePossibleCircles (NodeDescription <?> nodeDescription , Set <NodeDescription <?>> visitedNodes , Predicate <PropertyFilter .RelaxedPropertyPath > includeField , PropertyFilter .RelaxedPropertyPath path ) {
570
573
Collection <RelationshipDescription > relationships = ((DefaultNeo4jPersistentEntity <?>) nodeDescription ).getRelationshipsInHierarchy (includeField , path );
571
574
572
575
for (RelationshipDescription relationship : relationships ) {
573
- if (processedRelationships .contains (relationship )) {
576
+ NodeDescription <?> targetNode = relationship .getTarget ();
577
+ if (visitedNodes .contains (targetNode )) {
574
578
return true ;
575
579
}
576
- processedRelationships .add (relationship );
577
- if (calculatePossibleCircles (relationship . getTarget (), processedRelationships , includeField , path .append (relationship .getFieldName ()))) {
580
+ visitedNodes .add (targetNode );
581
+ if (calculatePossibleCircles (targetNode , new HashSet <>( visitedNodes ) , includeField , path .append (relationship .getFieldName ()))) {
578
582
return true ;
579
583
}
580
584
}
0 commit comments