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!