本文介绍了为什么@Transactional(Propagation.NOT_SUPPORTED)不能按预期工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下内容:

  1. 在类级别使用@Transactional(Propagation.REQUIRED)开始集成测试.
  2. 插入某些参考数据,并在方法级别指定Propagation.NOT_SUPPORTED.
  3. 标记为@Transactional(Propagation.REQUIRED)的服务方法尝试查找在步骤2中插入的一些参考数据.
  1. An integration test is started using @Transactional(Propagation.REQUIRED) at class level.
  2. Some reference data is inserted with Propagation.NOT_SUPPORTED specified at method level.
  3. A service method marked as @Transactional(Propagation.REQUIRED) attempts to look up some reference data inserted in step 2.

服务方法看不到参考数据!

The service method can't see the reference data!

我的理解是,如果将数据插入到事务外部,则无论是在事务内部还是外部,其他方法都可以立即访问它们.有人可以解释吗?

My understanding was that if data is inserted outside the transaction, it would be instantly accessible to another method whether it is inside or outside the transaction. Could anyone explain?

推荐答案

不是一个完整的答案,但我认为这些麻烦部分是由于在总体事务中运行集成测试引起的-本文解释了为什么这是一个坏主意.我打算尝试将所有数据填充重写为非事务性,并在每次测试结束时手动清除.

Not a complete answer but I think these woes are partially caused by running integration tests inside an overarching transaction - this article explains why this is a bad idea. Am going to attempt to rewrite all the data population to be non-transactional and cleared up manually at the end of each test.

这篇关于为什么@Transactional(Propagation.NOT_SUPPORTED)不能按预期工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 06:53