gpt4 book ai didi

java - Neo4j Java 驱动程序事务似乎未提交

转载 作者:行者123 更新时间:2023-11-30 06:58:18 28 4
gpt4 key购买 nike

我正在使用 Ne04j v3.1.0 和 Java 驱动程序。我无法在显式事务中获取更新语句(密码集)的结果以进行持久化。交易内的返回值显示了更改,但交易结束后,更改似乎消失了。我知道更新对结果处理很敏感

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

因此,我在代码中一直积极地消耗所有结果并关闭 session 。

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

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"

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

如果有任何帮助,我将不胜感激。

最佳答案

我未能执行txn.success()

关于java - Neo4j Java 驱动程序事务似乎未提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41399972/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com