Created nodes don't appear to be added to the neo4j database -


I have created some nodes in a neo4j database from within a groovy app, but when I connect to the database by using databases I'm a shell client who does not look there.

I am creating what is described in the database:

  def graphDb = new GraphDatabaseFactory (). NewEmbeddedDatabase () "/tmp/foo.db"); Transaction tx = graphDb.beginTx () def firstNode = graphDb.createNode (); FirstNode.setProperty ("Message", "Hello,"); Def secondNode = graphDb.createNode (); SecondNode.setProperty ("Message", "World!"); Tx.success (); System.err.print (firstNode.getProperty ("Message")); System.err.print (relationship.getProperty ("Message")); System.err.print (secondNode.getProperty ("Message")); After running the app, I can see that the database is built on the filesystem, although when I connect to the shell client, it seems that there is no node in the database:  
  $ ./neo4j-community-2.1.5/bin/neo4j-shell-path/tmp/foo.db/ -v neo4j-sh (?) $ Match (m) return m; + --- - | M | + + --- + --- + 0 rows  

What can I do wrong?

You did not close the transaction tx.success () just succeeded Marks the transaction as being, but it will not commit. Use tx.close () to use the transaction. While using Java, the best practice is to use the resource-of-resource blocks - it automatically counts against calling

  GraphDatabaseService graphDb = ...; Try (transaction tx = graphDb.beginTx ()) {// do stuff tx.success (); }  

Since your code has def , I assume that you are using groovy, which does not support efforts-of-resources The code looks like this:

  def graphDb = .... transaction tx = graphDb.beginTx () try {// do stuff eg make nodes tx.success ()} Finally {tx. Close ()}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -