Spring Data Neo4j loops if there is a cycle

Hello everyone,

How can I set the depth/limit the number of hops in Spring Data?

I'm using Neo4j DB with SDN, and since I have a cycle I keep getting an infinite loop.

I'm trying to retrieve all my nodes with the related relationships and target nodes with a depth of 1 (only one hop) with the following query:

MATCH p = (u1:User)-[r]->(u2:User) WITH *, relationships(p) AS r RETURN u1, collect(r), collect(u2)

My model is as follow:

@Node
public class User {

@Id
@GeneratedValue
private Long id;

@Property
private String name;

@Relationship(type="RELATED")
private List<Relationship> relationship;

//constructor, getter and setters 

}
@RelationshipProperties
public class Relationship{

@Id
@GeneratedValue
private Long id;

@Property
private String role;

@TargetNode
private User user;

//constructor, getter and setters 

}

I understood that to set the depth to 1 I should add *1 to the relation as below:

MATCH (u1:User})-[r*1]->(u2:User) RETURN u1, collect(r), collect(u2)

Neo4J flag that solution (adding *n) as deprecated an I should operate with a path, so I wrote the following query:

MATCH p = (u1:User)-[r]->(u2:User) WITH *, relationships(p) AS r RETURN u1, collect(r), collect(u2)

The previous query seems to work as intended if I try to execute it in Neo4J Browser but if executed in Spring Data I get an infinite loop

This is the query in my repository

@Query("MATCH p = (u1:User)-[r]->(u2:User) WITH *, relationships(p) AS r RETURN u1, collect(r), collect(u2)")
Collection<User> getAllUser();

The SDN version is 2.6.1
The DB version is 4.4.3

Do you have an idea of how I should approach this issue? Thank you!

Hello, +1 to this problem. Its not required to have actual cycle but its enough to entity of one type pointing to other of same type ex: Category1 -> Category2 -> Category3 (All kinds of tree).

Any solutions?

Its PropertyFilterSupport class of spring-data-neo4j:6.2.3 causing creation of infiniete path in this case (method addPropertiesFrom)
OGM seems to be much much better, its sad its not supported in new spring versions