如何在spring数据neo4j 4中查询路径?

时间:2015-10-06 04:58:47

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

在早期版本的spring数据neo4j(3.3.1)中,我能够查询数据库中的路径并将其作为Iterable<EntityPath<S,E>>返回,如下所示:

public interface ArgumentNodeRepository extends GraphRepository<ArgumentNode> {
    @Query("START t=node({0}), r=node({1}) MATCH p=t<-[:SUPPORTED_BY|INTERPRETS*0..]-r RETURN p")
    Iterable<EntityPath<ArgumentNode, ArgumentNode>> getPaths(long childId, long rootId);
}

我正在尝试迁移到4.0.0,而EntityPath类似乎已经消失了。我在migration guide中没有看到任何EntityPath。我的新退货类型是什么?

2 个答案:

答案 0 :(得分:3)

SDN 4不支持EntityPath,但您仍然可以查询路径。 我有一个示例here,其中包含一个返回路径的Cypher查询 - 返回类型为Iterable<Map<String, Object>>

这表示路径的集合,每个路径包含路径中的交错节点和关系列表(节点和关系表示为Map)。我如何处理路径的示例是https://github.com/luanne/flavorwocky/blob/sdn/src/main/java/com/flavorwocky/service/PairingServiceImpl.java#L57

答案 1 :(得分:0)

你也可以为此Neo4jOperations。 只需创建一个自定义存储库实现(参见http://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#repositories.custom-implementations),然后从那里调用Neo4jOperations bean:

neo4jOperations.queryForObjects(ArgumentNode.class, "START t=node({0}), r=node({1}) MATCH p=t<-[:SUPPORTED_BY|INTERPRETS*0..]-r RETURN p")

这将返回ArgumentNodes列表