【问题标题】:Neo4J: Execute SET/CREATE Cypher Query embedded in a Java processNeo4J:执行嵌入在 Java 进程中的 SET/CREATE Cypher 查询
【发布时间】:2015-10-09 08:20:43
【问题描述】:

我想在 Java 进程中执行密码查询 (link)。

这对于像MATCH xyz RETURN n 这样的所有查询都很好,但是每当我想执行和编写像CREATE 或SET 这样的操作时,就会引发异常:

Exception in thread "main" org.neo4j.graphdb.QueryExecutionException: The given query is not supported at the moment in the selected cost-based planner
at org.neo4j.kernel.impl.query.QueryExecutionKernelException.asUserException(QueryExecutionKernelException.java:35)
at org.neo4j.kernel.InternalAbstractGraphDatabase.execute(InternalAbstractGraphDatabase.java:970)
at org.neo4j.kernel.InternalAbstractGraphDatabase.execute(InternalAbstractGraphDatabase.java:957)
at MainClass.embTestQuery(MainClass.java:85)
at MainClass.main(MainClass.java:28)

代码片段:

    matchingQuery = "CREATE (n:testnode) RETURN n";
    try ( Transaction ignored = db.beginTx();
              Result result = 
                      db.execute( matchingQuery ))
        {
            while ( result.hasNext() )
            {
                Map<String,Object> row = result.next();
                for ( Entry<String,Object> column : row.entrySet() )
                {
                    rows += column.getKey() + ": " + column.getValue() + "; ";
                }
                rows += "\n";
            }
        }
    System.out.println(rows);

引用的库:

  • neo4j-consistency-check-2.2.5.jar
  • neo4j-csv-2.2.5.jar
  • neo4j-cypher-2.2.5.jar
  • neo4j-cypher-compiler-1.9-2.0.4.jar
  • neo4j-cypher-compiler-2.0-2.0.4.jar
  • neo4j-cypher-compiler-2.1-2.1.8.jar
  • neo4j-cypher-compiler-2.2-2.2.5.jar
  • neo4j-graph-algo-2.2.5.jar
  • neo4j-graph-matching-2.2.5.jar
  • neo4j-import-tool-2.2.5.jar
  • neo4j-io-2.2.5.jar
  • neo4j-jmx-2.2.5.jar
  • neo4j-kernel-2.2.5.jar
  • neo4j-lucene-index-2.2.5.jar
  • neo4j-primitive-collections-2.2.5.jar
  • lucene-core-3.6.2.jar
  • org.apache.servicemix.bundles.jline-0.9.94_1.jar
  • neo4j-shell-2.2.5.jar
  • neo4j-udc-2.2.5.jar
  • neo4j-unsafe-2.2.5.jar

【问题讨论】:

  • 你能分享你的代码吗?向我们展示您的尝试
  • 您的代码使用了哪些依赖项(jar)?
  • 添加了参考库和代码片段
  • GraphDatabaseSettings.read_only 已设置为 false
  • 尝试更改您的密码规划器:neo4j.com/docs/stable/…

标签: java neo4j cypher


【解决方案1】:

问题出在您的密码规划器上,在 Neo4j's Documentation 您可以了解如何执行密码查询。

上面这句话正好说明了你的问题:

默认情况下,Neo4j 2.2 将使用成本规划器进行一些查询,但不是全部。您可以通过使用 query.planner.version 配置设置(请参阅 dbms.cypher.planner)强制它使用特定的计划器,或者通过在查询前添加 CYPHER planner=cost 或 CYPHER planner=rule。 Neo4j 可能仍然不使用您选择的规划器 — 此时成本规划器无法解决所有查询。请注意,使用 PLANNER COST 或 PLANNER RULE 在规划器之间切换已被弃用,并且在未来版本中将停止工作。

修复

要解决此问题,您只需在数据库配置文件中更改密码规划器(有关指南,请参阅 dbms.cypher.planner documentation)。

【讨论】:

  • 我们确认可以通过将数据库配置“dbms.cypher.planner”设置为“COST”来重现此问题。所以很可能这就是所做的事情,最好不要设置这个配置(允许数据库为工作选择最佳规划器),或者按照 Supamiu 的描述设置每个查询。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-12
相关资源
最近更新 更多