2

I am able to create nodes and relationships through Java on a Neo4j database. When I try to access the created nodes in the next run I get this error:

Exception in thread "main" org.neo4j.graphdb.NotFoundException: Node 27 not found

In webadmin interface the dashboard shows the number of nodes/relationships created through Java, but when I issue this query: START n=node(*) RETURN n; I get only 1 node in the ouput.

(FYI I have installed Ne04j in my windows machine(local) and using embedded database java code to create nodes.) Java code I used to connect to db:

final String dbpath = "C:\\neo4j-community-1.9.4\\data\\graph.db";      
GraphDatabaseService graphdb =  new GraphDatabaseFactory().newEmbeddedDatabase(dbpath);

The settings I have used in ne04j-server.properties are:

org.neo4j.server.database.location=/C:/neo4j-community-1.9.4/data/graph.db/
org.neo4j.server.webserver.https.keystore.location=data/keystore
org.neo4j.server.webadmin.rrdb.location=data/rrd
org.neo4j.server.webadmin.data.uri=/C:/neo4j-community-1.9.4/data/graph.db/
org.neo4j.server.webadmin.management.uri=/db/manage/

When I create node through Java the data/keystore file does not get populated, and only gets populated when creating a node through webadmin interface. Changing the path of keystore file to absolute path also did not work.

Can anybody point the mistake in this scenario, Thanks .

1
  • You seem to interact with the database both as embedded instance and as server. (Are you aware of the differences?) Forgetting about the server and its webadmin and configuration files for the moment, are you able to persist your data to an embedded instance and read it back? Commented Oct 7, 2013 at 10:51

3 Answers 3

2

The problem was the nodes created were not comitted. To commit the nodes we got to give finish() :

try{
Transaction tx = graphdb.beginTx();
final String dbpath = "/C:/neo4j-community-1.9.4/data/graph.db/";
GraphDatabaseService graphdb =  new GraphDatabaseFactory().newEmbeddedDatabase(dbpath);
Node n1 = graphdb.createNode();
n1.setProperty("type", "company");
n1.setProperty("location", "india");
....
...
}} catch(Exception e){
   tx.failure();
} finally {
   tx.success();
  **tx.finish();**
}
Sign up to request clarification or add additional context in comments.

1 Comment

You should probably move tx.success() before your catch, you don't want to call success in the exceptional case.
1

Ranjith's answer was correct until recently, but tx.finish() has now been deprecated.

tx.close(); is now the correct way to commit or rollback the transaction - it will do one or the other depending on whether you've previously called tx.success().

They changed this so the transaction is autocloseable in a try with resources block.

Comments

0

Have you tried:

String dbpath = "C:/neo4j-community-1.9.4/data/graph.db"; 

3 Comments

Thanks for your reply Max. Yes I tried it now and no luck, I guess the problem might be with these two properties: org.neo4j.server.webserver.https.keystore.location=data/keystore org.neo4j.server.webadmin.rrdb.location=data/rrd ..
Yes only set the org.neo4j.server.database.location property
By setting the org.neo4j.server.webadmin.data.uri property I do not see the nodes in webadmin, once I comment that and set only the org.neo4j.server.database.location the webadmin interface works neat. Thanks for your reply Micheal...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.