3

There's sometime I must be missing about neo4j 3.0 embedded. After creating a node, setting some properties, and marking the transaction as success. I then re-open the DB, but there are no nodes in it! What am I missing here? The neo4j documentation is pretty poor.

      val graph1 = {
        val graphDb = new GraphDatabaseFactory()
          .newEmbeddedDatabase(new File("/opt/neo4j/deviceGraphTest" ))
        val tx = graphDb.beginTx()
        val node = graphDb.createNode()
        node.setProperty("name", "kitchen island")
        node.setProperty("bulbType", "incandescent")
        tx.success()
        graphDb.shutdown()
      }

      val graph2 = {
        val graphDb2 = new GraphDatabaseFactory()
          .newEmbeddedDatabase(new File("/opt/neo4j/deviceGraphTest" ))
        val tx2 = graphDb2.beginTx()
        val allNodes = graphDb2.getAllNodes.iterator().toList
        allNodes.foreach(node => {
          printNode(node)
        })
      }
4
  • 1
    I think you have to call tx.close() or tx.finish() after tx.success() to close the transaction. Can you try that?
    – K.E.
    Jan 9, 2017 at 7:18
  • Correct! Thanks K.E.! How about submitting an answer?
    – scalapeno
    Jan 9, 2017 at 14:15
  • Perfect - Did you use tx.close() or tx.finish()? Tell me, then I will write an answer.
    – K.E.
    Jan 9, 2017 at 14:26
  • Yep, tx.close()
    – scalapeno
    Jan 11, 2017 at 17:17

1 Answer 1

1

The transaction what you have opened has to be closed with the command tx.close() after setting the transaction to state success. I do not know the exact scala syntax but it would be good to put the full block into a try/catch and to finally close the transaction in the finally block. Here is the documentation for Java: https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/Transaction.html

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.