我目前正在使用neo4j 1.8.1。我得到NotInTransactionException,当我查询neo4j索引来获取一些节点。查询neo4j索引时获取NotInTransactionException
下面是一个简单的查询,其中我对Neo4j的
if (graphDb.index().existsForNodes("NODEINDEX")) {
IndexHits<Node> hits = graphDb.index().forNodes(NODEINDEX).query(query);
}
执行以下是异常堆栈跟踪。
"message" : "Error fetching transaction for current thread",
"exception" : "NotInTransactionException",
"stacktrace" : [ "org.neo4j.kernel.impl.index.IndexConnectionBroker.getCurrentTransaction(IndexConnectionBroker.java:134)", "org.neo4j.kernel.impl.index.IndexConnectionBroker.acquireReadOnlyResourceConnection(IndexConnectionBroker.java:84)", "org.neo4j.index.impl.lucene.LuceneIndex.getReadOnlyConnection(LuceneIndex.java:105)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:245)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:227)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:238)", "com.uprr.netcontrol.starmap.neo4j.plugins.aggregate_node_status.NodeStatusHelper.getGraphNodes(NodeStatusHelper.java:39)",
我在Neo4j api中发现了以下内容。
private Transaction getCurrentTransaction() throws NotInTransactionException
{
try
{
return transactionManager.getTransaction();
}
catch (SystemException se)
{
throw new NotInTransactionException(
"Error fetching transaction for current thread", se);
}
}
我们是否需要明确启动一个查询neo4j索引的事务?
有什么想法?
感谢
刚开始执行查询之前就开始了一个事务吗? – Rolf 2013-03-20 16:19:59
由于这是一个读取事务,因此我没有明确指出有关索引的任何事务 – Subbu 2013-03-21 08:38:18
,但我的猜测是需要明确的事务,但即使只读取也是如此。 – Rolf 2013-03-21 14:54:18