gpt4 book ai didi

java - Neo4j 3.5 中的事务未实现 java.lang.AutoCloseable

转载 作者:行者123 更新时间:2023-12-01 06:21:59 25 4
gpt4 key购买 nike

我已经安装了 Neo4j社区版 3.5.0-alpha07,并且我正在尝试创建一个简单的,其中包含以下两个节点this教程。问题是来自 org.neo4j.graphdb.Transaction 的关键字 Transaction 显示语法错误。代码如下:

Operation.java

import java.io.File;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

public class Operation {

//private static final File file =new File();

public static void main(String[] args) {

GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
GraphDatabaseService db= dbFactory.newEmbeddedDatabaseBuilder("C:\\Users\\pritom.mazumdar\\Downloads\\neo4j-community-3.5.0-alpha07\\data\\databases\\graph.db").newGraphDatabase();
//Transaction tx = db.beginTx();
try (Transaction tx = db.beginTx()) {

The resource type Transaction does not implement java.lang.AutoCloseable

            Node javaNode = db.createNode();
javaNode.setProperty("TutorialID", "JAVA001");
javaNode.setProperty("Title", "Learn Java");
javaNode.setProperty("NoOfChapters", "25");
javaNode.setProperty("Status", "Completed");

Node scalaNode = db.createNode();
scalaNode.setProperty("TutorialID", "SCALA001");
scalaNode.setProperty("Title", "Learn Scala");
scalaNode.setProperty("NoOfChapters", "20");
scalaNode.setProperty("Status", "Completed");

Relationship relationship = javaNode.createRelationshipTo(scalaNode, (RelationshipType) Label.label("JVM_LANG"));
relationship.setProperty("Id","1234");
relationship.setProperty("OOPS","YES");
relationship.setProperty("FP","YES");

tx.success();
}
System.out.println("Done successfully");

}

}

我已经尝试实现AutoCloseable覆盖close方法,但它仍然不起作用,语法错误仍然存​​在。

最佳答案

这是因为 try-with-resources 只接受 AutoCloseable 对象。编译器说 Transaction 不是 AutoCloseable

关于java - Neo4j 3.5 中的事务未实现 java.lang.AutoCloseable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51935200/

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