neo4j中的循环递归调用



我正试图使用spring-data-neo4j在neo4j数据库中输入几个图节点。

节点具有以下关系。

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层或类似层上,对吧?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

最新更新