简体   繁体   English

Spring Data Neo4j如何开始交易工作?

[英]How does Spring Data Neo4j begin transaction work?

I have a comprehension question. 我有一个理解问题。 I cannot understand how the database actions from the Neo4jTemplate like "getOrCreateNode()" belong to the surrounding transction. 我无法理解Neo4jTemplate中的数据库操作(如“ getOrCreateNode()”)如何属于周围的事务。 How is it implemented? 如何实施? The Neo4jTemplate would be shared in a multi-threaded environment? Neo4jTemplate将在多线程环境中共享吗? I cannot see a distinct membership of the transaction. 我看不到交易的不同成员身份。 I would understand if the actions are directly in the transaction object (eg tx.getOrCreateNode()). 我将了解这些操作是否直接在事务对象中(例如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();
  }
}

Thanks in advance. 提前致谢。

The below extract from the reference documentation pretty much sums it up. 下面从参考文档中摘录的内容大致总结了一下。 Use the spring transaction manager instead of using the Neo4j transactions and let spring take care of demarcation. 使用spring事务管理器代替使用Neo4j事务,让spring处理边界。 Also, the transaction management is completely thread-safe. 而且,事务管理是完全线程安全的。 For you, I suggest using @Transactional annotation. 对于您来说,我建议使用@Transactional批注。 If there is an existing transaction already, then spring joins that existing transaction as well. 如果已经存在一个现有事务,那么spring也将加入该现有事务。

Transactions 交易

The Neo4jTemplate provides implicit transactions for some of its methods. Neo4jTemplate为某些方法提供隐式事务。 For instance save uses them. 例如保存使用它们。 For other modifying operations please provide Spring Transaction management using @Transactional or the TransactionTemplate . 对于其他修改操作,请使用@TransactionalTransactionTemplate提供Spring事务管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM