arangodb/spring-data

Self-referential Relations cause Stackoverflow Error

nwiecz1 opened this issue · 2 comments

Hello,

I have a collection and edge similarly to below:

@Collection("person")
public class Person {
    private String name;
   // other fields and getters/setters omitted

  @Relations("relatives")
  private List<Person> relatives;
}

@Edge("relatives")
public class Relatives {
  @From
  private Person person1;

  @To
  private Person person2;
}

Insertion of the above using spring-data classes works great. When I try to query with a simple findById, I am getting a stack overflow error. If I change the relations to be outbound only, it works fine for person1 but if I query for person2 they won't know about person1. If I change it to an inbound only on the relations annotation, that cases the stack overflow error. It looks like it find the edge and keeps descending down and re-finding the same edge until it crashes.

I've tried add lazy eval, maxDepth, etc and the error persists. When I create a graph query in the arango gui, the query below works fine and does not keep re-querying:

WITH person, relatives 
  FOR v,e,p in 1..1 ANY @id GRAPH @graph RETURN p

Any idea how to make this work with spring-data without having to write a custom query? The Relations documentation page in the arango docs seems to indicate this should work, but I only get stack overflow errors.

I solved this by explicitly creating a JsonSerializer for my Person collection that removes any recursion issues. Please ignore. Thanks!

@nwiecz1
Setting lazy=true is expected to work in this case. A similar case is tested here:

@Relations(edges = Knows.class, lazy = true)

Please reopen and add details in case you find further problems.