【发布时间】:2016-10-27 21:52:18
【问题描述】:
数据模型:
我有一个存储在 neo4j 中的树形结构,其中:Node 类型的节点可以是相同类型节点的父节点。
:Node 节点显示在右侧。树的根(显示为红色)与叶子共享一些属性,因此有一个抽象类称为AbstractNode:
public abstract class AbstractNode {
private Long id;
@NotEmpty
private String code;
@Relationship(type = "SUBTREE_OF", direction = Relationship.INCOMING)
private Set<Node> children;
<getters & setters omitted>
}
父节点的类:
public class CodeSet extends AbstractNode {
@Relationship(type = "SUBTREE_OF", direction = Relationship.OUTGOING)
private Application parent;
<getters and setters omitted>
}
子节点的类:
public class Node extends AbstractNode {
@NotEmpty
private String description;
@NotEmpty
private String type;
@NotEmpty
private String name;
@NotNull
@Relationship(type = "SUBTREE_OF", direction = Relationship.OUTGOING)
private AbstractNode parent;
<getters and setters omitted>
}
服务层:
此方法用于将节点信息检索到指定深度:
@Transactional(readOnly = true)
public Node findById(Long id, int depth) throws EntityNotFoundException {
Node entity = nodeRepository.findOne(id, depth);
if (entity == null) {
throw new EntityNotFoundException(String.format("Node %d not found", id));
} else {
return entity;
}
}
问题:
在获取:Node 节点时,具有相同类型父节点的节点在子节点列表中具有这些父节点,这显然是错误的并导致其他问题。请参阅所描述数据集的调试器屏幕截图:
如何解决?
【问题讨论】:
-
您使用的是什么版本的SDN和OGM?
-
@digx1
org.springframework.data:spring-data-neo4j:4.1.2.RELEASE与对应的org.neo4j:neo4j-ogm-core:2.0.3
标签: java neo4j spring-data-neo4j neo4j-ogm nosql