我正在創建所有節點,然後添加所有關係。所有節點都存儲在HashMap中,該HashMap包含字符串名稱作爲鍵和節點作爲值,所以我可以輕鬆地獲得節點以創建關係。創建關係時出現Neo4j異常
for(Map.Entry<String[], Integer> entry: company_counts_backward.entrySet()){
String[] node_names = entry.getKey();
String company_from = node_names[0];
String company_to = node_names[1];
int count = entry.getValue();
Node companyFromNode = nodes_created.get(company_from);
Node companyToNode = nodes_created.get(company_to);
Relationship relationship = companyFromNode.createRelationshipTo(companyToNode, Relations.WORKED_AT);
relationship.setProperty("relationship-type", "knows");
relationship.setProperty("length", count);
}
請注意,這個for循環是由 Transaction tx = graphDB.beginTx();
tx.finish();
問題包圍的是,創建一個關係時,我似乎得到拋出Exception in thread "main" org.neo4j.graphdb.NotInTransactionException
。
完整的錯誤軌跡如下:
at org.neo4j.kernel.impl.persistence.PersistenceManager.getCurrentTransaction(PersistenceManager.java:284)
at org.neo4j.kernel.impl.persistence.PersistenceManager.getResource(PersistenceManager.java:249)
at org.neo4j.kernel.impl.persistence.PersistenceManager.currentKernelTransactionForReading(PersistenceManager.java:230)
at org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.transaction(ThreadToStatementContextBridge.java:53)
at org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.instance(ThreadToStatementContextBridge.java:47)
at org.neo4j.kernel.impl.core.NodeProxy.createRelationshipTo(NodeProxy.java:406)
誰能請找出並指出我在正確的方向在何處我錯了?