我试图执行tutoriel但是这个错误信息仍然存在
Exception in thread "main" org.neo4j.graphdb.NotInTransactionException
at org.neo4j.kernel.impl.persistence.PersistenceManager.getResource(PersistenceManager.java:228) at org.neo4j.kernel.impl.persistence.PersistenceManager.getResource(PersistenceManager.java:228)
at org.neo4j.kernel.impl.persistence.PersistenceManager.nodeCreate(PersistenceManager.java:155)
at org.neo4j.kernel.impl.core.NodeManager.createNode(NodeManager.java:254)
at org.neo4j.kernel.EmbeddedGraphDbImpl.createNode(EmbeddedGraphDbImpl.java:305)
at org.neo4j.kernel.EmbeddedGraphDatabase.createNode(EmbeddedGraphDatabase.java:105)
at twiapp.embeded.main(embeded.java:37)
Java Result: 1
答案 0 :(得分:1)
修改数据库的代码需要在事务中运行:
public static void main(String args[]) {
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(path);
registerShutdownHook(graphDb);
Transaction tx = graphDb.beginTx();
try {
firstNode = graphDb.createNode();
firstNode.setProperty("message", "Hello, ");
secondNode = graphDb.createNode();
secondNode.setProperty("message", "World!");
relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
relationship.setProperty("message", "brave Neo4j ");
tx.success();
} finally {
tx.finish();
}
}
您还应该使用提供的工厂创建嵌入式数据库。请参阅2.1.7版http://neo4j.com/docs/2.1.7/tutorials-java-embedded-hello-world.html
的教程