Lakini
Lakini

Reputation: 13

Unexpected NotInTransactionException exception

I'm trying to develop a J2EE application (in WildFly 8.2) that uses Neo4J 2.2.1 embedded . Since i'm migrating it from Neo4J 1.9, the application uses the indexing legacy system.

I'm experiencing problems during some operations that shouldn't returns exceptions related to a transaction.

For example:

for ( Iterator iterator = node.getPropertyKeys().iterator(); iterator.hasNext(); ) {
            key = (String)(iterator.next());
            ....
}

The stacktrace:

File (71):ThreadToStatementContextBridge.java -    org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.assertInUnterminatedTransaction
File (104):ThreadToStatementContextBridge.java - org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.getTopLevelTransactionBoundToThisThread
File (111):ThreadToStatementContextBridge.java - org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.getKernelTransactionBoundToThisThread
File (64):ThreadToStatementContextBridge.java - org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.instance
File (785):InternalAbstractGraphDatabase.java - org.neo4j.kernel.InternalAbstractGraphDatabase$8.statement
File (358):NodeProxy.java - org.neo4j.kernel.impl.core.NodeProxy.getPropertyKeys

Note that i got the same error if i call the following:

Index<Node> indexNode = ...
...
indexNode.get("users", "[email protected]").getSingle()

where indexNode is a previous created index in a transaction.

Any ideas?

Thank you

Upvotes: 1

Views: 118

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

The most impactful breaking changes from Neo4j 1.9 -> 2.0 was mandatory read transactions. Whenever you do read operations you need to have a transaction around that.

try (Transaction tx=graphDatabaseService.beginTx()) {
   // read stuff - either graph or index operations
   ...

   tx.success(); // make sure to have this, otherwise trouble might happen in case of nested transactions
}

Upvotes: 1

Related Questions