1

I am new at Neo4J and following the HelloWorld tutorial on the neo4j website ( http://docs.neo4j.org/chunked/milestone/tutorials-java-embedded-hello-world.html).

My purpose is to create 2 nodes and a relationship between them and finally observe this on the dashboard accessible via

[http://localhost:7474/webadmin/#] 

But the problem is that i am getting an error when i run my code and i don't know how to solve it.

Any help would be really appreciated

Thank you very much

Here is my code and the error

Code

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

public class HelloNeo4J {

private static enum RelTypes implements RelationshipType
{
    KNOWS
}

public static String DB_PATH= " /home/anas/graph/data/graph.db/" ; 

public static void main ( String[] args){

    GraphDatabaseService graphDb= new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
    Node firstNode, secondNode;
    Relationship relationship;

    Transaction tx = graphDb.beginTx();
    try
    {
        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();
    }
    finally
    {
        tx.finish();
    }

}
}

Error

Exception in thread "main" org.neo4j.kernel.lifecycle.LifecycleException: Failed to transition org.neo4j.kernel.AbstractGraphDatabase$DefaultKernelExtensionLoader@691f36 from NONE to STOPPED
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:388)
at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:82)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:116)
at org.neo4j.kernel.AbstractGraphDatabase.run(AbstractGraphDatabase.java:224)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:79)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:70)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:195)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:56)
at HelloNeo4J.main(HelloNeo4J.java:20)
Caused by: java.lang.VerifyError: class org.neo4j.kernel.InternalAbstractGraphDatabase overrides final method getStoreDir.()Ljava/lang/String;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.neo4j.index.lucene.LuceneIndexProvider.load(LuceneIndexProvider.java:65)
at org.neo4j.kernel.AbstractGraphDatabase$DefaultKernelExtensionLoader.loadIndexImplementations(AbstractGraphDatabase.java:1180)
at org.neo4j.kernel.AbstractGraphDatabase$DefaultKernelExtensionLoader.init(AbstractGraphDatabase.java:1152)
at  org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:382)
    ... 8 more
inf3rno
  • 24,976
  • 11
  • 115
  • 197
Anas
  • 437
  • 6
  • 19
  • 1
    Which version of Neo4j are you using? Maybe your version is different than the example code. – tstorms Mar 27 '13 at 15:11
  • i am using this one : Neo4j - Graph Database Kernel 1.8.2 – Anas Mar 27 '13 at 15:15
  • 1
    The link your referring to is for the 1.9.M05 version. Maybe try the example code for 1.8.2? See http://docs.neo4j.org/chunked/1.8.2/tutorials-java-embedded-hello-world.html. – tstorms Mar 27 '13 at 15:34
  • You were right, it seems it was a version issue. the first time i run it, i got no error , but nothing's been added to db the second time i got this error (which disappear when i delete the graph folder) Mar 27, 2013 4:44:05 PM org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog doInternalRecovery INFO: Non clean shutdown detected on log [/home/anas/graph/data/graph.db/nioneo_logical.log.1]. Recovery started ... – Anas Mar 27 '13 at 15:44
  • Actually , i got no error , but nothing has been added to the database ! i mean i didn't see the nodes i created on the dashboard ! – Anas Mar 27 '13 at 15:53
  • Can you go to the "data browser" tab and enter "START n=node( * ) RETURN count( * )". What's the result? – tstorms Mar 27 '13 at 15:56
  • i am having as a result 1, which seems to be the root node – Anas Mar 27 '13 at 16:01

2 Answers2

3

There are two issues,

First: INFO: Non clean shutdown detected on log ... Recovery started

The information you see, is because you didn't cleanly shut-down your database with db.shutdown(), so it has to recover non-applied transaction logs.

Second:

If you want to see your results in the Neo4j-Server you have to use the same db-directory as in conf/neo4j-server.properties and you MUST stop the server while you are writing data to it.

Oherwise you can also run the server on top of your embedded db, see: http://docs.neo4j.org/chunked/milestone/server-embedded.html

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • Thanks Michael ! Actually i was afraid that the injection of nodes wasn't successful as i didn't see anything on the dashboard. But i could verify it through the neo4j-shell by selecting the database path i used in my java code, and got my data using a simple cypher query on it – Anas Mar 28 '13 at 10:28
  • Hello again, i changed the path-to-db in my code to the path `/db/data/` used by the Neo4J server and that is located in the file `conf/neo4j-server.properties` Nevertheless, i can **only** check on the **shell** that inserts have succeed, but i still cannot see this on the **Neo4J administration interface**. Could you give me more details about this please ? – Anas Mar 28 '13 at 15:39
  • 1
    I found the solution here `http://stackoverflow.com/questions/10888280/neo4j-how-to-switch-database` – Anas Mar 29 '13 at 08:13
  • So, to observe the data in the graph database, i have modified the file `conf/neo4j-server.properties`and changed the line which references the database that is being used by the neo4j server like this: `org.neo4j.server.webadmin.data.uri="path-to-the-database" `. `path-to-the-database` was in my case `" /home/anas/graph/data/graph.db/"` – Anas Mar 31 '13 at 13:34
0

Please implement a graph database (a kind of NoSQL). This graph database should consist of nodes (with have properties) for entities and edges (which have single or multiple properties and can be directional or bidirectional) for relationships, and support node indexing and query. The query language has following keywords: START, MATCH, WHERE, RETURN, ORDER BY, AGGREGATE, SKIP, and LIMIT.