Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session.run() VS transaction.run() in Neo4j Bolt

What is the difference between the Session.run() and transaction.run() in Neo4j Bolt driver?

My knowledge is:

Session.run() will execute a single statement    
transaction.run() executes multiple statements.

Those are the information I know which are correct. What are the all other differences?

like image 307
Jack Daniel Avatar asked Sep 16 '16 07:09

Jack Daniel


1 Answers

Session.run() will actually create a transaction, execute the statement, and commit the transaction. Transaction.run() will leave the transaction open until you commit it, but the statement will still be sent and interpreted and executed, and results will be returned. However, any changes won't actually be persisted into the datastore, and won't be visible to queries outside of the transaction. You have to mark the transaction as successful and commit it or it will be rolled back.

You should try not to use transactions; open transactions prevent changes to indexes and constraints and increase memory usage. The only reason to use transactions is for the rollback potential; if you want to see what the results of the query are, and maybe undo it depending on those results, then use a transaction. Otherwise use a session.

like image 192
Tore Eschliman Avatar answered Oct 20 '22 07:10

Tore Eschliman