嵌入式Neo4j在JVM中

时间:2016-07-12 21:47:42

标签: java neo4j

我正在尝试从我的java程序访问neo4j数据库。我尝试创建一个新的数据库并对其进行查询,并按以下方式成功运行:http://neo4j.com/docs/java-reference/current/#tutorials-java-embedded

代码:

String DB_PATH = "C:/Users/singsand/Documents/Neo4j/newdb";
    File f=new File(DB_PATH);
    GraphDatabaseService graphDb =   new GraphDatabaseFactory().newEmbeddedDatabase(f);
    try (Transaction tx=graphDb.beginTx()){
        graphDb.execute("CREATE (table1:car {name:'car1'})");
        tx.success();
    }

但后来我通过Neo4j社区版工具将这个数据库作为服务器启动,并通过我的浏览器访问它。

之后,当我执行上面使用的相同java程序时,它会抛出以下错误:

    Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.CommunityFacadeFactory, C:\Users\singsand\Documents\Neo4j\newdb
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:144)
    at org.neo4j.kernel.impl.factory.CommunityFacadeFactory.newFacade(CommunityFacadeFactory.java:40)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:108)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:100)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$193(GraphDatabaseFactory.java:89)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:65)
    at neo4j.neo4jdemo.App.main(App.java:41)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.recovery.Recovery@62fca613' failed to initialize. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:416)
    at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:98)
    at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:508)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:434)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:99)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:434)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:140)
    ... 7 more
Caused by: java.lang.IllegalArgumentException: Unrecognized log entry version -9. At position LogPosition{logVersion=0, byteOffset=16} and entry version null
    at org.neo4j.kernel.impl.transaction.log.entry.LogEntryVersion.byVersion(LogEntryVersion.java:147)
    at org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader.readLogEntry(VersionAwareLogEntryReader.java:83)
    at org.neo4j.kernel.impl.transaction.log.LogEntryCursor.next(LogEntryCursor.java:50)
    at org.neo4j.kernel.recovery.LatestCheckPointFinder.find(LatestCheckPointFinder.java:77)
    at org.neo4j.kernel.recovery.PositionToRecoverFrom.apply(PositionToRecoverFrom.java:53)
    at org.neo4j.kernel.recovery.DefaultRecoverySPI.getPositionToRecoverFrom(DefaultRecoverySPI.java:112)
    at org.neo4j.kernel.recovery.Recovery.init(Recovery.java:72)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:406)
    ... 16 more

我在其他Stack Overflow问题中看到了类似的错误,但是无法使用他们的解决方案来解决我的问题。

1 个答案:

答案 0 :(得分:1)

如果我理解正确的话。您在应用程序中使用的是Neo4j的嵌入式版本,而不是尝试在本地主机上启动Neo4j服务器。是吗?

Neo4j Server vs Embedded mode

Neo4j embedded正在作为Java应用程序的一部分运行。 Neo4j服务器是独立服务,单独运行。而且你不能在同一个数据库中将这两者结合起来。

如果您想将Neo4j浏览器与嵌入式数据库一起使用,这应该可以帮助您 - http://graphaware.com/neo4j/2014/11/21/neo4j-browser-with-embedded.html