【问题标题】:Neo4j Java Driver Transaction Seems Not to CommitNeo4j Java 驱动程序事务似乎没有提交
【发布时间】:2016-12-30 17:10:24
【问题描述】:

我正在使用带有 Java 驱动程序的 Ne04j v3.1.0。我无法在显式事务中获取更新语句(密码 SET)的结果以保持不变。事务中的返回值显示了更改,但在事务结束后,更改似乎消失了。我知道更新对结果处理很敏感

[http://neo4j.com/docs/developer-manual/current/drivers/process-results/][1]

所以我在我的代码中一直积极地使用所有结果并关闭我的会话。

我写了一个测试程序来演示这个问题:

package uk.co.scapps.createdirs.neo;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.Transaction;


public class Trans {
    static Driver driver = GraphDatabase.driver("bolt://localhost", AuthTokens.basic("neo4j", "neo4k"));
    static Session session = driver.session();
    final static Logger logger = LogManager.getLogger();

    public static void main(String[] args) {
        session = driver.session();
        StatementResult results ;
        session = driver.session();
        try (Transaction tx = session.beginTransaction()) {
            results = tx.run("MATCH (n:THING) RETURN n.name as name");
            while (results.hasNext()) {
                Record record = results.next();
                System.out.println("in the txn before the update: " + record.get("name").toString());
            }           
            results.consume();
            results = tx.run("MATCH (n:THING {name: 'a'}) SET n.name = 'asdasd' RETURN n.name as name");
            while (results.hasNext()) {
                Record record = results.next();
                System.out.println("results returned from the update: " + record.get("name").toString());
            }           
            results.consume();
            results = tx.run("MATCH (n:THING) RETURN n.name as name");
            while (results.hasNext()) {
                Record record = results.next();
                System.out.println("after the update but still in the txn: " + record.get("name").toString());
            }           
            results.consume();
            tx.close();
            session.close();
        }
        session = driver.session();
        results = session.run("MATCH (n:THING) RETURN n.name as name");
        while (results.hasNext()) {
            Record record = results.next();
            System.out.println("after the txn: " + record.get("name").toString());
        }           
        results.consume();
        session.close();
    }
}

这是输出:

in the txn before the update: "a"
in the txn before the update: "b"
in the txn before the update: "c"
results returned from the update: "asdasd"
after the update but still in the txn: "asdasd"
after the update but still in the txn: "b"
after the update but still in the txn: "c"
after the txn: "a"
after the txn: "b"
after the txn: "c"

我没有包含代码,但我编写了一个非事务(隐式事务)版本的程序,它按预期工作。

我将不胜感激。

【问题讨论】:

    标签: java neo4j transactions


    【解决方案1】:

    我未能执行txn.success()

    【讨论】:

    • 您可能需要考虑删除问题,或接受您自己的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    相关资源
    最近更新 更多