简体   繁体   中英

Neo4j visualizing and retrieving data

Starting to use Neo4j embedded with my JAVA web server. While saving the data the transaction was successful, but not able to visualize the data via browser.

Have tried sample Hello world from tutorial . And installed neo4j community edition, after pointing to DB and navigating to http://localhost:7474/browser/ i don't see any data.

Also, when i stop the application and run Cypher query via Java not getting any data.

Maven dependency used

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>2.3.1</version>
        </dependency>

Sample code written

try {
   Transaction tx = graphDb.beginTx();
   firstNode = graphDb.createNode();
   firstNode.setProperty( "message", "Hello, " );
   secondNode = graphDb.createNode();
   secondNode.setProperty( "message", "World!" );

   relationship = firstNode.createRelationshipTo( secondNode,     RelTypes.KNOWS );
   relationship.setProperty( "message", "brave Neo4j " );
   tx.success();
}

DB path for embedded as well as server is same.

I do not know exact root of the issue. But I have checklist, that should be verified.

1) You application and Neo4j server should use same database. When you are creating embdedded database via GraphDatabaseFactory you are specifying database location. Same database location should be specified for Neo4j server in conf/neo4j-server.properties file ( org.neo4j.server.database.location option).

2) You should NOT use database simultaneously in server and application. Database can be used only by one Neo4j instance at a time.

3) Use try-with-resource syntax for transactions. It is available in Java7 and later. Example:

try (Transaction tx = db.beginTx()) {
    // do stuff 
    tx.success();
}

In this way transaction will be always closed, in any case (even if exception occurs during execution, or in beginTx() ).

4) Ensure that your database is closed in “clean way”. In application it can be done via db.shutdown() method. Server can be stopped via bin/neo4j stop .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM