我在 Neo4j 数据库中有以下实体:
public class CompetencyEntity {
@GeneratedValue(strategy = UuidStrategy.class)
@Id
private String id;
@Property
private String name;
@Relationship(type = "PARENT_OF", direction = Relationship.OUTGOING)
private List<CompetencyEntity> children;
@Relationship(type = "PARENT_OF", direction = Relationship.INCOMING)
private List<CompetencyEntity> parents;
public void setParentOf(CompetencyEntity competency) {
children.add(competency);
}
public void setNotParentOf(CompetencyEntity competency) {
children.removeIf(comp -> comp.id.equals(competency.id));
}
}
我想查询数据库,以便它返回所有没有定义父项的实体。我想使用@Repository界面自动生成的查询来完成它。这样做可以让我轻松添加@Depth参数。
我的存储库如下:
@Repository
public interface CompetencyRepository
extends Neo4jRepository<CompetencyEntity, String>, CrudRepository<CompetencyEntity, String> {
Set<CompetencyEntity> findByNameRegex(String name);
@Query("MATCH (n:CompetencyEntity) WHERE NOT (n)<-[:PARENT_OF]-(:CompetencyEntity) RETURN n")
Set<CompetencyEntity> findRootCompetencies();
@Query("MATCH (n:CompetencyEntity) WHERE NOT (:CompetencyEntity)<-[:PARENT_OF]-(n) RETURN n")
Set<CompetencyEntity> findChildrenCompetencies();
Set<CompetencyEntity> findByChildrenEmpty();
Set<CompetencyEntity> findByParentsEmpty();
}
查询findRootCompetencies确实有效。但是当我尝试findByParentsEmpty()(应该意味着“找到被调用的列表parents为空的实体)方法时,它会抛出以下内容Exception
精慕HU
相关分类