Reputation: 1221
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.
My Java code is :
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();
}
}
}
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
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)
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!
Upvotes: 0
Views: 773
Reputation: 1221
Able to solve this challenge. Mention complete DB_PATH. Thanks everyone who had given there time for this.
Upvotes: 0
Reputation: 54212
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.
Upvotes: 2