我对 Neo4j 很陌生。我正在使用版本2.0.0-M05
。
GraphDatabaseService.index()
如果在事务之外调用,为什么会抛出异常?我可以让它在没有交易的情况下工作吗?
这是我的示例代码
val graphDb = new GraphDatabaseFactory().
newEmbeddedDatabaseBuilder("test_db").
setConfig(GraphDatabaseSettings.node_keys_indexable, "nodeProp1,nodeProp2").
setConfig(GraphDatabaseSettings.relationship_keys_indexable, "relProp1,relProp2").
setConfig(GraphDatabaseSettings.node_auto_indexing, "true").
setConfig(GraphDatabaseSettings.relationship_auto_indexing, "true").
newGraphDatabase()
val userIndex = graphDb.index().forNodes("user")
导致以下异常
Exception in thread "main" org.neo4j.graphdb.NotInTransactionException
at org.neo4j.kernel.impl.transaction.AbstractTransactionManager.assertInTransaction(AbstractTransactionManager.java:108)
at org.neo4j.kernel.IndexManagerImpl.assertInTransaction(IndexManagerImpl.java:465)
at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:300)
at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:293)
at Test$.main(Test.scala:77)
at Test.main(Test.scala)
PS。它不会发生在1.9.RC1
.