通过java检索neo4j节点数据时出错 [英] Error while retrieving neo4j node data through java
问题描述
我已经通过talend加载了大约60k个节点到neo4j。我想通过java访问这些节点。 Java代码只能获取带有neo4j本身的单个节点,即第0个节点。
I have loaded about 60k nodes into neo4j through talend. I want to get access to these nodes through java. Java code is only able to fetch a single node which comes with neo4j itself i.e. 0th node.
我的Java代码是:
package com.Neo4J;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.naming.spi.DirStateFactory.Result;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.helpers.collection.IteratorUtil;
import org.neo4j.kernel.impl.util.FileUtils;
import org.neo4j.tooling.GlobalGraphOperations;
public class CaseNeo4J {
private static final String DB_PATH = "data/graph.db";
GraphDatabaseService graphDataService;
String nodeResult, resultString, columnsString;
String rows = "";
public static void main(String args[]) {
CaseNeo4J neoobj = new CaseNeo4J();
neoobj.connect();
}
void connect() {
graphDataService = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
Transaction transaction = graphDataService.beginTx();
try {
ExecutionEngine engine = new ExecutionEngine(graphDataService);
ExecutionResult result = engine.execute("START n = node(0) return n");
System.out.println(result.dumpToString());
}
finally {
transaction.finish();
}
}
}
我试图退出节点(0),这给我正确的结果为
As you can see in CQL I am trying to retireve node(0) which is giving me correct result as
+-----------+
| n |
+-----------+
| Node[0]{} |
+-----------+
1 row
但是一旦我给出像 START n = node(1)return n 这样的查询,它会抛出错误 -
But as soon as I give query like START n = node(1) return n it throws errors as-
Exception in thread "main" org.neo4j.cypher.EntityNotFoundException: Node 1 not found
at org.neo4j.cypher.internal.spi.gdsimpl.GDSBackedQueryContext$$anon$1.getById(GDSBackedQueryC ontext.scala:80)
at org.neo4j.cypher.internal.spi.gdsimpl.GDSBackedQueryContext$$anon$1.getById(GDSBackedQueryC ontext.scala:48)
at org.neo4j.cypher.internal.executionplan.builders.NodeByIdBuilder$$anonfun$org$neo4j$cypher$ internal$executionplan$builders$NodeByIdBuilder$$f$1$1.apply(NodeByIdBuilder.scala:41)
at org.neo4j.cypher.internal.executionplan.builders.NodeByIdBuilder$$anonfun$org$neo4j$cypher$ internal$executionplan$builders$NodeByIdBuilder$$f$1$1.apply(NodeByIdBuilder.scala:41)
at org.neo4j.cypher.internal.executionplan.builders.GetGraphElements$.org$neo4j$cypher$interna l$executionplan$builders$GetGraphElements$$castElement$1(GetGraphElements.scala:30)
at org.neo4j.cypher.internal.executionplan.builders.GetGraphElements$$anonfun$getElements$3.ap ply(GetGraphElements.scala:40)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
at scala.collection.Iterator$$anon$13.next(Iterator.scala:372)
at org.neo4j.cypher.internal.ClosingIterator$$anonfun$next$1.apply(ClosingIterator.scala:44)
at org.neo4j.cypher.internal.ClosingIterator.failIfThrows(ClosingIterator.scala:86)
at org.neo4j.cypher.internal.ClosingIterator.next(ClosingIterator.scala:43)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at org.neo4j.cypher.internal.ClosingIterator.foreach(ClosingIterator.scala:31)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:178)
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:259)
at org.neo4j.cypher.internal.ClosingIterator.to(ClosingIterator.scala:31)
at scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:243)
at org.neo4j.cypher.internal.ClosingIterator.toList(ClosingIterator.scala:31)
at org.neo4j.cypher.PipeExecutionResult.eagerResult(PipeExecutionResult.scala:100)
at org.neo4j.cypher.PipeExecutionResult.dumpToString(PipeExecutionResult.scala:103)
at org.neo4j.cypher.PipeExecutionResult.dumpToString$lzycompute(PipeExecutionResult.scala:143)
at org.neo4j.cypher.PipeExecutionResult.dumpToString(PipeExecutionResult.scala:140)
at org.neo4j.cypher.javacompat.ExecutionResult.dumpToString(ExecutionResult.java:102)
at com.Neo4J.CaseNeo4J.connect(CaseNeo4J.java:45)
at com.Neo4J.CaseNeo4J.main(CaseNeo4J.java:32)
但是如果我跑 START n = node(1)return n 这个查询在neo4j shell的web UI中,它给了我正确的结果。
But if I ran START n = node(1) return n this query in web UI of neo4j shell it gives me correct result.
这个?我真的很感激,如果我得到一些解决方案。谢谢!
Is there any idea on this? I will really appreciate if I get some solution here. Thanks!
推荐答案
确定使用与neo4j服务器实例和talend使用的DB_PATH相同的数据位置吗?你能检查绝对路径吗? AFAIK当您在没有数据的路径上启动嵌入式数据库实例时,它会从头创建一个只包含ID为0的根节点的空数据集。
Are you sure you are pointing to the same data location with DB_PATH as used by the neo4j server instance and talend? Can you check the absolute paths, please? AFAIK when you start an embedded database instance on a path where no data exists it creates an empty data set from scratch that only contains a root node with the id 0.
这篇关于通过java检索neo4j节点数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!