[英]Spring-Data-Neo4j annotated Cypher Query, match paramter
I'm trying to parametrize the match part of a annotated Cypher query with Spring-Data-Neo4j-3.1.4 as follows. 我正在尝试使用Spring-Data-Neo4j-3.1.4参数化带注释的Cypher查询的匹配部分,如下所示。 The first method is working. 第一种方法有效。 Passing the node type as parameter in the second method fails. 在第二种方法中将节点类型作为参数传递失败。
public interface NodeRepository extends CrudRepository<Node, Long> {
@Query("START n=node(*) MATCH (n:Organization) RETURN n")
List<Node> findByNodeType();
@Query("START n=node(*) MATCH (n:{0}) RETURN n")
List<Node> findByNodeType(String nodeType);
}
Exception is: 例外是:
org.springframework.dao.InvalidDataAccessResourceUsageException:
Error executing statement START n=node(*) MATCH (n:{0}) RETURN n;
nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException:
Error executing statement START n=node(*) MATCH (n:{0}) RETURN n;
nested exception is Invalid input '{':
expected whitespace or a label name (line 1, column 26)
"START n=node(*) MATCH (n:{0}) RETURN n"
at org.springframework.data.neo4j.support.query.CypherQueryEngineImpl.query(CypherQueryEngineImpl.java:61)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:107)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery$1.doWithGraph(GraphRepositoryQuery.java:89)
at org.springframework.data.neo4j.support.Neo4jTemplate.doExecute(Neo4jTemplate.java:457)
at org.springframework.data.neo4j.support.Neo4jTemplate.access$000(Neo4jTemplate.java:87)
at org.springframework.data.neo4j.support.Neo4jTemplate$2.doInTransaction(Neo4jTemplate.java:471)
How do pass the node as a parameter to the Cypher query? 如何将节点作为参数传递给Cypher查询?
Change your queries to: MATCH (n:Organization) RETURN n
将查询更改为: MATCH (n:Organization) RETURN n
You can try: MATCH (n) WHERE {0} IN labels(n) RETURN n
您可以尝试: MATCH (n) WHERE {0} IN labels(n) RETURN n
but it won't be efficient, why would you want to do that in the first place ? 但是效率不高,为什么首先要这么做?
Labels are not allowed as parameters (yet) for query-planner reasons. 由于查询计划者的原因,尚未将标签用作参数。
If you read the exception : Invalid input '{':
如果您读取异常: Invalid input '{':
It means that the query is wrong. 这意味着查询是错误的。 In fact you cannot pass labels as parameter in a Cypher query, so simple it is ;-) 实际上,您无法在Cypher查询中将标签作为参数传递,这很简单; ;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.