【问题标题】:Cyclic recursion call in neo4jNeo4j中的循环递归调用
【发布时间】:2021-01-11 22:08:40
【问题描述】:

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

节点具有以下关系。

Project -> Cluster -> Entity -> MethodsEntity节点与自己的节点有关系,是双向的关系。

实体类定义如下。

@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)(通过引用链:

【问题讨论】:

  • 是 thi private Set&lt;Entity&gt; entityIdr; 没有引起这个循环递归吗?

标签: spring neo4j spring-data-neo4j neo4j-ogm


【解决方案1】:

我假设您尝试序列化数据并将其公开在 Web 层或类似层上,对吗? jackson 序列化需要获取更多关于如何打破 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

【讨论】:

    猜你喜欢
    • 2016-08-09
    • 2012-11-17
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 2021-02-08
    • 1970-01-01
    相关资源
    最近更新 更多