我有一个理解问题。我无法理解 Neo4jTemplate 中的数据库操作(如“getOrCreateNode()”)如何属于周围事务。它是如何实现的? Neo4jTemplate 会在多线程环境中共享吗?我看不到该交易的独特成员资格。我会理解这些操作是否直接在事务对象中(例如 tx.getOrCreateNode())。
@Service
public class TestService {
@Autowired
private Neo4jTemplate template;
public void save(IndexedTriple triple) {
GraphDatabase gdb = template.getGraphDatabase();
Transaction tx = gdb.beginTx();
Node subject = gdb.getOrCreateNode()
...
tx.success();
tx.finish();
}
}
提前致谢。
最佳答案
以下摘录自 reference documentation总结得差不多了。使用 spring 事务管理器而不是使用 Neo4j 事务,并让 spring 负责划分。此外,事务管理是完全线程安全的。对于您来说,我建议使用 @Transactional
注释。如果已经存在一个现有事务,那么 spring 也会加入该现有事务。
Transactions
The Neo4jTemplate provides implicit transactions for some of its methods. For instance save uses them. For other modifying operations please provide Spring Transaction management using
@Transactional
or theTransactionTemplate
.
关于java - Spring Data Neo4j 如何开始事务工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18528142/