Gökhan Çoban
Gökhan Çoban

Reputation: 610

Using node index via Neo4j java api

Neo4j documentation says that, read operations don't require to be in a transaction.

In the code below,

// graphDB and name variables defined somewhere.
graphDB.index().forNodex("indexKey").get("name", name);

"index", "forNodes" and even "get" functions of api require to be called in a transaction, how I know, they all begin with "assertInTransaction();" line.

What's the recommended usage of index? Should they be surrounded by a transaction all the time?

Upvotes: 0

Views: 83

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41706

It always needs a read transaction, the code is wrong if there is not one.

Upvotes: 1

Related Questions