无法查询Neo4j存储库

时间:2017-04-28 22:21:30

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

嘿大家我对Neo4j很新,并且在查询我的存储库时遇到了问题。

存储库如下:

   public interface NodeOneRepository extends GraphRepository<NodeOne> {
       List<NodeOne> findByNodeTwoNodeThreeAndActiveTrue(NodeThree nodeThree);
   }

我的实体如下:

@NodeEntity(label = "NodeOne")
public class NodeOne {
  @GraphId
  private Long id;

  private Boolean active = TRUE;

  @Relationship(type = "IS_ON")
  private NodeTwo nodeTwo;
}

@NodeEntity(label = "NodeTwo")
public class NodeTwo {
  @GraphId
  private Long id;

  @Relationship(type = "CONTAINS", direction = "INCOMING")
  private NodeThree nodeThree;

  @Relationship(type = "IS_ON", direction = "INCOMING")
  private List<NodeOne> nodeOnes = new ArrayList<>();
}

@NodeEntity(label = "NodeThree")
public class NodeThree {
  @GraphId
  private Long id;

  @Relationship(type = "CONTAINS")
  private List<NodeTwo> nodeTwos = new ArrayList<>();
}

Getters&amp;塞特斯省略。当我调用该方法时,我得到一个空列表。有什么我做错了吗?

1 个答案:

答案 0 :(得分:2)

你没有准确描述你想要达到的目标,但我可以看到两个问题:

问题1:

当前版本的Spring Data Neo4j和OGM仅允许嵌套查找程序(即指定关系属性的查找程序)达到一个深度。

支持的

findByNodeTwoSomePropertyAndActiveTrue(String relatedNodePropertyValue)

不支持

findByNodeTwoNodeThree //Nesting relationships in finders is not supported

问题2:

派生的查找程序允许匹配属性和嵌套属性。不是该类的整个实例。

您可以使用自定义查询实现所需的功能。

@Query("custom query here")
List<NodeOne> findByNodeTwoNodeThreeAndActiveTrue(NodeThree nodeThree);

如果您需要帮助来编写自定义查询,可以发布其他问题或加入neo4j-users公共冗余频道。

相关问题