-
Notifications
You must be signed in to change notification settings - Fork 618
Description
We encountered a problem in Spring Data Neo4j when a domain entity contains both incoming and outgoing relationships, and the query returns a deeply nested / complex graph structure (with the same nodes being connected through multi-level in/out relationships).
In such cases, the DefaultNeo4jEntityConverter recursively resolves the relationships and keeps creating nested entities.
When the returned subgraph is deep enough, the recursive mapping ends up consuming too many stack frames and eventually causes a java.lang.StackOverflowError.

@query("""
MATCH (c:analyzer)
WHERE c.id IN $0
CALL apoc.path.subgraphAll(c, {
relationshipFilter: 'child>',
maxLevel: $1
})
YIELD nodes, relationships
UNWIND nodes AS node
OPTIONAL MATCH (node)-[r:child]->(a:analyzer)
RETURN node, collect(r),collect(a)
""")
List findAllChildren(Set tableIds, int maxLevel);
public class TableNode extends HiBaseNode {
@Relationship(type = Neo4jConstants.RelationShip.CHILD, direction = Relationship.Direction.INCOMING)
private Set<TableNode> parentNodes;
@Relationship(type = Neo4jConstants.RelationShip.CHILD)
private Set<TableNode> childNodes;
}
We observed that after increasing the JVM thread stack size (-Xss) the conversion succeeds, which indicates that the problem is caused by deep recursion during property filling.