本文介绍了使用动态节点标签运行Cypher Query时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在尝试通过动态Cypher查询获取数据.但是却遇到了如下异常:

Hello i'm trying to get data by a dynamic Cypher query.. However got an exception like:

org.neo4j.rest.graphdb.query.CypherTransactionExecutionException: Error executing cypher statements [{code=Neo.ClientError.Statement.InvalidSyntax, message=Invalid input '{': expected whitespace or a label name (line 1, column 54)
"MATCH (parentNode:ParentEntity)-[:HAS_A]->(childNode:{dynamicChildEntityType})= WHERE id(parentNode)={parentNodeId}  RETURN childNode order by childNode.orderNr"
                                                      ^}]

在尝试调用方法时:

@Override
public List<ChildEntity> getChildrenOf(Long parentNodeId, String dynamicChildEntityType) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("dynamicChildEntityType", dynamicChildEntityType);
    params.put("parentNodeId", parentNodeId);


    String cql = "MATCH (parentNode:ParentEntity)-[:HAS_A]->(childNode:{dynamicChildEntityType})= WHERE id(parentNode)={parentNodeId}  RETURN childNode order by childNode.orderNr";


    return parentRepository.query(cql, params).as(List.class);

}

您看到什么地方了吗?标签不能使用参数吗?如果是这样,您有什么建议?

can you see what is wrong?Can't i use parameters for labels? If so, what do you suggest?

提前谢谢.

注意:我在Rest Api上使用Neo4j v2.1.6.

Note: i'm using Neo4j v2.1.6 over Rest Api.

推荐答案

您不能在Cypher中使用参数化标签.这样做的理由是,不同的标签可能会导致一个完整的单独的查询计划.想想带有索引的标签,其他没有索引的标签,等等.Cypher会为参数化的Cypher字符串缓存查询计划,因此无法将标签作为参数.

You cannot use parameterized labels in Cypher. The rationale for this is that a different label might result in a complete separate query plan. Think of labels having an index, other without indexes, etc. Cypher caches the query plan for a parameterized Cypher string, therefore it's not possible to have labels as parameters.

对于标签和关系类型,您需要在客户端使用字符串连接.

For labels and relationship types you need to use string concatenation on the client side.

这篇关于使用动态节点标签运行Cypher Query时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:45