spring-data-neo4j没有将参数替换为@Query

时间:2013-05-07 16:30:45

标签: neo4j spring-data-neo4j

我已经在Neo4j Web界面中测试了我的查询,现在我想将它添加到我的Java程序中。我试过这个(在名为Track的@NodeEntity类中):

@Query("START n=({self}) MATCH (n)-->(x)<--(y) RETURN y")
private Iterable<Track> alternativeTracks;

此外(在GraphRepository扩展接口中):

@Query("START n={track} MATCH (n)-->(x)<--(y) RETURN y")
public Iterable<Track> findAlternativeTracks(@Param("track") Track track);

也是位置版本:

@Query("START n={0} MATCH (n)-->(x)<--(y) RETURN y")
public Iterable<Track> findAlternativeTracks(Track track);

但每次我得到这个例外和追踪:

Exception in thread "main" org.neo4j.rest.graphdb.RestResultException: expected either node or relationship here
"START n=({self}) MATCH (n)-->(x)<--(y) RETURN y"
          ^ at
SyntaxException
   org.neo4j.cypher.internal.parser.v1_8.CypherParserImpl.parse(CypherParserImpl.scala:45)
   org.neo4j.cypher.CypherParser.parse(CypherParser.scala:42)
   org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:67)
   org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:67)
   org.neo4j.cypher.internal.LRUCache.getOrElseUpdate(LRUCache.scala:37)
   org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:67)
   org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:59)
   org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:63)
   org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79)
   org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:67)
   java.lang.reflect.Method.invoke(Method.java:597)

将'self'替换为'track'或'0',具体取决于我正在尝试的版本。

我一直在翻阅文档和示例,但我似乎无法弄清楚我在这里缺少什么。谁能开导我?

(我在spring-data-neo4j版本2.2.1.RELEASE)

1 个答案:

答案 0 :(得分:2)

使用节点对象作为参数时,需要将其包装在node()中。即。节点({self})而不仅仅是({self})。

修正如下:

@Query("START n=node({self}) MATCH (n)-->(x)<--(y) RETURN y")
private Iterable<Track> alternativeTracks;