Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-10-2020 01:00 AM
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?
Solved! Go to Solution.
11-11-2020 12:33 AM
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() { /.../ });
}
11-11-2020 12:33 AM
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() { /.../ });
}
All the sessions of the conference are now available online