在Java中执行Cypher查询到Neo4j服务器时出现UnsupportedOperationException

时间:2012-12-10 23:29:20

标签: java neo4j

我正在使用以下Cypher nad查询Neo4j服务器,它可以正常工作:

GraphDatabaseService neo4j = new RestGraphDatabase("http://my.ip:7474/db/data");
ExecutionEngine engine = new ExecutionEngine(
String myCypher = "START n = node(1234) RETURN n LIMIT 10;"
ExecutionResult result = engine.execute(myCypher);
System.out.println(result);

如果我将查询的第一行更改为START n = node(*) RETURN n LIMIT 10;,当我尝试打印结果时,我会遇到这个丑陋的异常

  

线程“main”java.lang.UnsupportedOperationException中的异常       at org.neo4j.rest.graphdb.AbstractRemoteDatabase.getNodeManager(AbstractRemoteDatabase.java:144)       在org.neo4j.rest.graphdb.RestGraphDatabase.getNodeManager(RestGraphDatabase.java:33)       在org.neo4j.tooling.GlobalGraphOperations。(GlobalGraphOperations.java:39)       在org.neo4j.tooling.GlobalGraphOperations.at(GlobalGraphOperations.java:51)       在org.neo4j.cypher.internal.executionplan.builders.GraphGlobalStartBuilder $$ anonfun $ createStartPipe $ 1.apply(GraphGlobalStartBuilder.scala:51)       在org.neo4j.cypher.internal.executionplan.builders.GraphGlobalStartBuilder $$ anonfun $ createStartPipe $ 1.apply(GraphGlobalStartBuilder.scala:51)       在org.neo4j.cypher.internal.pipes.StartPipe $$ anonfun $ 1.apply(StartPipe.scala:38)       在org.neo4j.cypher.internal.pipes.StartPipe $$ anonfun $ 1.apply(StartPipe.scala:37)       在scala.collection.TraversableLike $$ anonfun $ flatMap $ 1.apply(TraversableLike.scala:200)       在scala.collection.TraversableLike $$ anonfun $ flatMap $ 1.apply(TraversableLike.scala:200)       在scala.collection.LinearSeqOptimized $ class.foreach(LinearSeqOptimized.scala:59)       在scala.collection.immutable.List.foreach(List.scala:45)       在scala.collection.TraversableLike $ class.flatMap(TraversableLike.scala:200)       在scala.collection.immutable.List.flatMap(List.scala:45)       在org.neo4j.cypher.internal.pipes.StartPipe.createResults(StartPipe.scala:37)       在org.neo4j.cypher.internal.pipes.MatchPipe.createResults(MatchPipe.scala:31)       在org.neo4j.cypher.internal.pipes.NamedPathPipe.createResults(NamedPathPipe.scala:26)       在org.neo4j.cypher.internal.pipes.FilterPipe.createResults(FilterPipe.scala:28)       在org.neo4j.cypher.internal.pipes.ExtractPipe.createResults(ExtractPipe.scala:37)       在org.neo4j.cypher.internal.pipes.EagerAggregationPipe.createResults(EagerAggregationPipe.scala:49)       在org.neo4j.cypher.internal.pipes.ExtractPipe.createResults(ExtractPipe.scala:37)       在org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:39)       在org.neo4j.cypher.internal.pipes.EagerAggregationPipe.createResults(EagerAggregationPipe.scala:49)       在org.neo4j.cypher.internal.pipes.ExtractPipe.createResults(ExtractPipe.scala:37)       在org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:39)       在org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl $$ anonfun $ 4 $$ anonfun $ apply $ 2.apply(ExecutionPlanImpl.scala:95)       在org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl $$ anonfun $ 4 $$ anonfun $ apply $ 2.apply(ExecutionPlanImpl.scala:95)       在org.neo4j.cypher.PipeExecutionResult.immutableResult(PipeExecutionResult.scala:37)       在org.neo4j.cypher.PipeExecutionResult.iterator(PipeExecutionResult.scala:153)       在org.neo4j.cypher.PipeExecutionResult.hasNext(PipeExecutionResult.scala:155)       在scala.collection.Iterator $$ anon $ 19.hasNext(Iterator.scala:334)       在scala.collection.Iterator $$ anon $ 19.hasNext(Iterator.scala:334)       在scala.collection.Iterator $ class.toString(Iterator.scala:1030)       在scala.collection.Iterator $$ anon $ 19.toString(Iterator.scala:333)       at java.lang.String.valueOf(String.java:2826)       在scala.collection.mutable.StringBuilder.append(StringBuilder.scala:185)       在scala.collection.TraversableOnce $$ anonfun $ addString $ 1.apply(TraversableOnce.scala:287)       在scala.collection.Iterator $ class.foreach(Iterator.scala:660)       在scala.Product $$ anon $ 1.foreach(Product.scala:38)       在scala.collection.TraversableOnce $ class.addString(TraversableOnce.scala:285)       在scala.Product $$ anon $ 1.addString(Product.scala:38)       在scala.collection.TraversableOnce $ class.mkString(TraversableOnce.scala:263)       在scala.Product $$ anon $ 1.mkString(Product.scala:38)       在scala.runtime.ScalaRunTime $ ._ toString(ScalaRunTime.scala:175)       在scala.collection.JavaConversions $ IteratorWrapper.toString(JavaConversions.scala:561)       at java.lang.String.valueOf(String.java:2826)       在java.io.PrintStream.println(PrintStream.java:771)

此外,System.out.println(result.columns())之类的工作正常,我可以从控制台完美地执行所有操作......发生了什么事?

编辑:

查询似乎返回得太快,我应该做些什么'让java等待'以获得完整的响应?

2 个答案:

答案 0 :(得分:2)

不要那样做!

使用new RestCypherQueryEngine(restGraphDb.getRestAPI())代替,否则所有查询都在客户端上运行,每个数据库访问都通过网络进行。

并确保在查询中使用参数。

使用:

QueryResult<Map<String, Object>> query(String statement, Map<String, Object> params)

答案 1 :(得分:0)

从这篇文章: https://stackoverflow.com/a/6953423/1498109

我猜您正在尝试将对象/数组转换为System.out.println(result)

处的字符串