0
votes

I have uploaded a CSV file and already have nodes and relationship defined on Neo4j. I've tried to create a program base on an example that basically run a cypher query from Spring that would generate the output from neo4j. However, I'm encountering this error:

Exception in thread "main" java.lang.NoSuchMethodError:org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(Ljava/io/File;)Lorg/neo4j/graphdb/GraphDatabaseService;
at org.neo4j.connection.Neo4j.run(Neo4j.java:43)
at org.neo4j.connection.Neo4j.main(Neo4j.java:37)

I'm wondering what could possibly be the error? Here is my code:

public class Neo4j{
public enum NodeType implements Label{
    Issues, Cost, Reliability, Timeliness;
}
public enum RelationType implements RelationshipType{
    APPLIES_TO
}

String rows = "";
String nodeResult;
String resultString;
String columnString;
private static File DB_PATH = new File("/Users/phaml1/Documents/Neo4j/default.graphdb/import/");

public static void main(String[] args){
    Neo4j test = new Neo4j();
    test.run();
}
void run()
{   

    clear();
    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);

    try(Transaction tx1 = db.beginTx();
            Result result = db.execute("MATCH(b:Business)-[:APPLIES_TO]->(e:Time) RETURN b,e"))
    {
        while(result.hasNext())
        {
            while ( result.hasNext() )
            {
                Map<String,Object> row = result.next();
                for ( Entry<String,Object> column : row.entrySet() )
                {
                    rows += column.getKey() + ": " + column.getValue() + "; ";
                }
                rows += "\n";
        }
    }

    try (Transaction something = db.beginTx();
            Result result1 = db.execute("MATCH(b:Business)-[:APPLIES_TO]->(e:Time) RETURN b,e"))
    {
        Iterator<Node> n_column = result.columnAs("n");
        for(Node node: Iterators.asIterable(n_column))
        {
            nodeResult = node + ": " + node.getProperties("Description");
        }
        List<String> columns = result.columns();
        columnString = columns.toString();
        resultString = db.execute("MATCH(b:Business)-[:APPLIES_TO]->(e:Time) RETURN b,e").resultAsString();
    }

    db.shutdown();
    }
}

private void clear(){
    try{
        deleteRecursively(DB_PATH);
    }
    catch(IOException e){
        throw new RuntimeException(e);
    }
}

}

1

1 Answers

0
votes

It looks like a Neo4j version conflict.

GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);

has a String as the argument in Neo4j 2x (https://neo4j.com/api_docs/2.0.3/org/neo4j/graphdb/factory/GraphDatabaseFactory.html#newEmbeddedDatabase(java.lang.String))

but a File in Neo4j 3x (http://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/factory/GraphDatabaseFactory.html#newEmbeddedDatabase-java.io.File-)

SDN is probably pulling in Neo4j 2.3.6 as a dependency- please check your dependency tree and override the Neo4j version