我正在使用Neo4jOperations来查询neo。 Spring正在获取节点及其父节点,但也正在获取显然我不感兴趣的父节点的子节点。我只想要节点的直接父节点和子节点。
@Repository
public class PracticeAreaRepository {
@Autowired
Neo4jOperations template;
public PracticeArea get(String uuid){
PracticeArea practiceArea = template.findByIndexedValue(PracticeArea.class, "practiceAreaId", uuid).singleOrNull();
template.fetch(practiceArea.getChildren());
template.fetch(practiceArea.getParent());
return practiceArea;
}
}
PracticeArea.java
@NodeEntity
public class PracticeArea {
@GraphId
private Long id;
private String name;
@Indexed
@GraphProperty(propertyName = "practice_area_id")
private UUID practiceAreaId;
@RelatedTo(type = "HAS_PARENT_PRACTICE_AREA", direction = Direction.OUTGOING)
PracticeArea parent;
@RelatedTo(type = "HAS_CHILD_PRACTICE_AREA", direction = Direction.OUTGOING)
Set<PracticeArea> children;
/* Getters & Setters */ ....
}
如何阻止Spring neo4j执行此操作?
答案 0 :(得分:0)
然后不要打电话:
template.fetch(practiceArea.getParent());
或者实际上,如果该父级的子级尚未加载到当前线程中,则该调用不应该获取该父级的子级。