使用org.springframework.data.neo4j.repository时的参数化查询问题

时间:2018-10-18 14:07:55

标签: neo4j spring-data-neo4j

@Query("match p=(self:Person {id:{id}})-[*1..{distance}]-(N) return collect(N)")
PersonConn findNeighbor2(@Param("id") String id,@Param("distance") String distance);

我的第一个参数id运行良好,但是当我添加距离参数并运行查询时,出现如下语法错误

org.neo4j.ogm.exception.CypherException: Error executing Cypher "Neo.ClientError.Statement.SyntaxError"; Code: Neo.ClientError.Statement.SyntaxError; Description: Parameter maps cannot be used in MATCH patterns (use a literal map instead, eg. "{id: {param}.id}") (line 1, column 38 (offset: 37))

“ match p =(self:Person {id:{id}})-[* 1 .. {distance}]-(N)

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您不能将内联深度文字作为参数传递,但是您可以将查询更改为:

@Query("match p=(self:Person {id:{id}})-[*]-(N) WHERE length(p) <= {distance} return collect(N)")
PersonConn findNeighbor2(@Param("id") String id,@Param("distance") String distance);