Neo4jClient Transactions

We have been using the Neo4jClient for handling all our query needs. What would be the preferred method of handling these queries in a transaction?

Basically you are using (Spring) transactions implicitly already.
Every use of the Neo4jClient creates a new or participates in an ongoing transaction.

Having said this, to combine those operations into one transaction you could either use the -probably more common approach- @Transactional annotation on your unit-of-work method like this

@Transactional
public void doSomeWork() {
    neo4jClient.doThis();
    neo4jClient.doThat();
}

Or you are using theTransactionTemplate:

private TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);

public void doSomeWork() {
    transactionTemplate.execute(status -> {
        neo4jClient.doThis();
        neo4jClient.doThat();
        return something;
    });
   // in case there is nothing to return
   transactionTemplate.execute(new TransactionCallbackWithoutResult() { /.../ });
}
1 Like