Created nodes don't appear to be added to the neo4j database -
i’ve created couple of nodes in neo4j database within groovy app, when connect database using shell client don’t appear there.
the database i’m creating described in http://neo4j.com/docs/stable/tutorials-java-embedded-hello-world.html:
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")); graphdb.shutdown()
after running app, can see database has been created on filesystem, when connect shell client, appears there no nodes in database:
$ ./neo4j-community-2.1.5/bin/neo4j-shell -path /tmp/foo.db/ -v neo4j-sh (?)$ match (m) homecoming m; +---+ | m | +---+ +---+ 0 row
what might doing wrong?
you didn't close transaction. tx.success()
marks transaction beingness successful won't commit it. finishing transaction utilize tx.close()
. best practice utilize try-with-resources blocks when doing java - cares calling close()
automatically.
graphdatabaseservice graphdb = ...; seek (transaction tx = graphdb.begintx()) { // stuff tx.success(); }
since code has def
assume you're using groovy, not back upwards try-with-resources. hence code looks like:
def graphdb = .... transaction tx = graphdb.begintx() seek { // stuff e.g. create nodes tx.success() } { tx.close() }
neo4j
No comments:
Post a Comment