cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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?

1 ACCEPTED SOLUTION

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

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