Neo4J:执行Java进程中嵌入的SET/createcypher查询

Neo4J:执行Java进程中嵌入的SET/createcypher查询,java,neo4j,cypher,Java,Neo4j,Cypher,我想在Java进程()中执行cypher查询 这对于所有查询(如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 o

我想在Java进程()中执行cypher查询

这对于所有查询(如
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);
matchingQuery=“创建(n:testnode)返回n”;
try(事务被忽略=db.beginTx();
结果=
db.execute(匹配查询))
{
while(result.hasNext())
{
Map row=result.next();
for(条目列:row.entrySet())
{
行+=column.getKey()+”:“+column.getValue()+”;”;
}
行+=“\n”;
}
}
系统输出打印项次(行);
参考图书馆:

  • 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

问题来自您的密码计划者,您可以了解密码查询是如何执行的

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

默认情况下,Neo4j 2.2将使用cost planner进行某些查询,但不是全部查询。您可以通过使用query.planner.version配置设置(请参阅dbms.cypher.planner)或使用cypher planner=cost或cypher planner=rule预先结束查询,强制它使用特定的计划器。Neo4j可能仍然不使用您选择的计划器 — 此时,并非所有查询都可由成本计划员解决。请注意,已不推荐使用“计划者成本”或“计划者规则”在计划者之间切换,并将在将来的版本中停止工作

修复
要解决此问题,您只需在数据库配置文件中更改cypher planner(请参阅以获取指南)。

您能分享您的代码吗?向我们展示您尝试了什么代码使用了哪些依赖项(JAR)?added ref lib和code fragmentGraphDatabaseSettings.read_only已设置为False尝试更改您的cypher planner:我们确认,通过将数据库配置“dbms.cypher.planner”设置为“COST”,可以重现此问题。因此,很可能就是这样做的,最好不设置此配置(允许数据库为作业选择最佳计划器),或者按照Supamiu所述的每个查询设置此配置。