neo4j中的循环递归调用

问题描述

我正在尝试使用spring-data-neo4j在neo4j db中输入几个图节点。

节点之间具有以下关系。

Project -> Cluster -> Entity -> Methods实体节点与其自己的节点具有关系,使其成为双向关系。

实体类定义如下。

@JsonIdentityInfo(generator =  ObjectIdGenerators.PropertyGenerator.class,property = "id")
@NodeEntity
public class Entity {
        public int id;
        public String type;
        public String name;
        public String entityId;
        Public String projectId;
        @Relationship(type = "CONNECTS_TO",direction = Relationship.INCOMING)
        private Set<Entity> entityIdr;

    }

尝试插入“群集”和“实体”节点时,抛出以下错误,有什么可能的解决方案以避免遵循该错误

com.fasterxml.jackson.databind.JsonMappingException:无限 递归(StackOverflowError)(通过参考链:

解决方法

我假设您尝试序列化数据并将其公开在Web层或类似的层上,对吗? 杰克逊序列化需要获得有关如何打破Java数据模型描述的周期的更多信息。 因此,要么忽略@JsonIgnore之类的属性,要么

@JsonIgnore
@Relationship(type = "CONNECTS_TO",direction = Relationship.INCOMING)
private Set<Entity> entityIdr;

,但至少在第一级看来就像是信息丢失, 或

@JsonIgnoreProperties("entityIdr")
@Relationship(type = "CONNECTS_TO",direction = Relationship.INCOMING)
private Set<Entity> entityIdr;

我们在Neo4j-OGM的文档中对此进行了编写:https://neo4j.com/docs/ogm-manual/current/reference/#_a_note_on_json_serialization