【问题标题】:My java programme is getting failed to update Neo4j DB我的 java 程序更新 Neo4j 数据库失败
【发布时间】:2013-10-02 04:41:29
【问题描述】:

我的本​​地 neo4j 数据库路径是 C:\neo4j-community-1.9.3_bup

我创建了一个简单的 java 程序来连接 neo4j 数据库并插入一些节点。

但是插入后的时候 我正在尝试通过 Neo4jDataBrower 检索这些未列出的节点。

我使用的代码取自 neo4j 门户本身,

    String DB_PATH = "C\\neo4j-community-1.9.3_bup";
    Map<String, String> config = new HashMap<String, String>();
    config.put( "neostore.nodestore.db.mapped_memory", "10M" );
    config.put( "string_block_size", "60" );
    config.put( "array_block_size", "300" );
    graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(DB_PATH).setConfig(config).newGraphDatabase();
    registerShutdownHook( graphDb );
    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();
    }

为什么它不起作用?

请给我建议..我给出的 vth 路径是否有问题或 vth 代码有问题?

嗨,维尔纳,

运行时异常是

Exception in thread "main" java.lang.RuntimeException:
 org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter@406199' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:280)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:106)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:88)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:207)
    at com.Neo4J.src.EmbeddedNeo4j.createDb(EmbeddedNeo4j.java:54)
    at com.Neo4J.src.EmbeddedNeo4j.main(EmbeddedNeo4j.java:38)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter@406199' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:497)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:104)
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:258)
    ... 5 more
Caused by: org.neo4j.kernel.StoreLockException: Could not create lock file
    at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:74)
    at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:40)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:491)
    ... 7 more

新日志,

Exception in thread "main" java.lang.RuntimeException: 

org.neo4j.kernel.lifecycle.LifecycleException: 

Component 'org.neo4j.kernel.impl.transaction.TxManager@1827284' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:280)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:106)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:88)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:207)
    at com.Neo4J.src.EmbeddedNeo4j.createDb(EmbeddedNeo4j.java:57)
    at com.Neo4J.src.EmbeddedNeo4j.main(EmbeddedNeo4j.java:41)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component
 'org.neo4j.kernel.impl.transaction.TxManager@1827284' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:497)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:104)
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:258)
    ... 5 more
Caused by: org.neo4j.graphdb.TransactionFailureException:
 Unable to start TM, no active tx log file found but found either tm_tx_log.1 or tm_tx_log.2 file, please set one of them as active or remove them.
    at org.neo4j.kernel.impl.transaction.TxManager.openLog(TxManager.java:750)
    at org.neo4j.kernel.impl.transaction.TxManager.start(TxManager.java:138)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:491)
    ... 7 more

新异常,

Sep 27, 2013 11:09:27 AM org.neo4j.server.logging.Logger log
INFO: Starting Neo Server on port [7474] with [40] threads available
2013-09-27 11:09:27.665:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
Sep 27, 2013 11:09:27 AM org.neo4j.server.logging.Logger log
INFO: Using database at C:\neo4j-community-1.9.3_bup\data\graph.db
Exception in thread "main" java.lang.NoSuchFieldError: remote_shell_enabled
    at org.neo4j.server.database.Database.createDatabase(Database.java:77)
    at org.neo4j.server.database.Database.<init>(Database.java:55)
    at org.neo4j.server.NeoServerWithEmbeddedWebServer.startDatabase(NeoServerWithEmbeddedWebServer.java:179)
    at org.neo4j.server.NeoServerWithEmbeddedWebServer.start(NeoServerWithEmbeddedWebServer.java:93)
    at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:87)
    at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:76)
    at com.Neo4J.src.EmbeddedNeo4j.createDb(EmbeddedNeo4j.java:69)
    at com.Neo4J.src.EmbeddedNeo4j.main(EmbeddedNeo4j.java:41)

【问题讨论】:

    标签: java neo4j node-neo4j


    【解决方案1】:

    C\\neo4j-community-1.9.3_bup 不是有效路径。应该是C:\\neo4j-community-1.9.3_bup。

    但是,如果您指向 Neo4J 安装目录,而不是数据库目录本身,它可能无效。如果是这样的话,路径应该是C:\\neo4j-community-1.9.3_bup\data\graph.db

    已编辑:

    为防止出现锁定情况,请停止正在运行的 Neo4J 实例,并使用自己的 Web 控制台启动您自己的数据库,方法是在初始化嵌入式数据库的行之后插入以下行:

    Configurator configurator = new ServerConfigurator((GraphDatabaseAPI)graphDb);
    configurator.configuration().setProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "127.0.0.1");
    configurator.configuration().setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, 7474);
    
    WrappingNeoServerBootstrapper bootstrapper = new WrappingNeoServerBootstrapper((GraphDatabaseAPI)graphDb, configurator);
    bootstrapper.start();
    

    【讨论】:

    • 您好 Werner,感谢您的回复,现在我已将路径替换为 C:\\neo4j-community-1.9.3_bup\data\graph.db。但是遇到运行时异常,我在上面添加了相同的内容..
    • 嗨,但是在程序中 graphDb 是 GraphDatabaseService 类型的,但是这里的构造函数需要 GraphDatabaseAPI。
    • 查看我的更新答案,我将graphDb 转换为GraphDatabaseAPI
    • 嗨 Werner,是的,我已经尝试过了,但即使出现了相同的运行时异常。我已经停止了 neo4j 实例并执行了这个,尽管同样的异常......
    • 我已经在我自己的电脑上成功启动了你的示例代码,没有任何问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多