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

时间:2018-08-20 16:44:32

标签: java neo4j

我已经安装了community edition 3.5.0-alpha07中的Neo4j,并且在this教程之后,我试图创建一个包含两个节点的简单graph。问题是Transaction中的关键字org.neo4j.graphdb.Transaction显示syntax error。代码如下:

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()) {
  

资源类型交易不实现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的{​​{1}}和overriding方法,但是仍然无法正常工作,语法错误反复出现。

1 个答案:

答案 0 :(得分:-2)

这是因为try-with-resources仅接受AutoClosable个对象。编译器说Transaction不是AutoClosable