我正在尝试使用 java api 为 Neo4j 中的节点设置属性。 目前我正在做如下:
tx.begin();
Node node = db.findNode(label,key,value);
node.setProperty("k",11);
tx.success();
但是,当我再次启动该过程并尝试检索此 key 或查看该特定节点中的值时,我看不到该 key 存在。如何着手?
最佳答案
Transaction.success仅标记交易成功。事务直到Transaction.close()才真正提交。被称为。
Transaction JavaDocs 声明如下:
Here's the idiomatic use of programmatic transactions in Neo4j starting from java 7:
try ( Transaction tx = graphDb.beginTx() ) { // operations on the graph // ... tx.success(); }
该成语使用了 try-with-resources语句以确保在语句退出时(即使由于异常)自动调用 tx.close()
。您的交易代码也应如此。
例如:
try (Transaction tx = db.beginTx()) {
Node node = db.findNode(label, key, value);
node.setProperty("k", 11);
tx.success();
}
关于java - 如何在 java 中为 Neo4j 节点设置节点的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49662559/