cancel
Showing results for 
Search instead for 
Did you mean: 

Neo4jClient Transactions

boyenvangorp
Node Clone

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?

1 ACCEPTED SOLUTION

gerrit_meier
Neo4j
Neo4j

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() { /.../ });
}

View solution in original post

1 REPLY 1

gerrit_meier
Neo4j
Neo4j

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() { /.../ });
}