【发布时间】:2010-06-24 14:14:01
【问题描述】:
我有一个类似下面的界面
public interface FooDAO {
public void callA(String x);
}
下面的实现故意使 readonly 为 true 且不受支持
public class FooDAOImpl implements FooDAO {
//for testing
@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
public void callA(String x) {
//sql update method
}
}
在我的 spring 上下文中,我声明了 Datasource 事务管理器和 tx:annotation-driven。我写了一个 Junit4 测试,看起来像
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(...)
@TransactionConfiguration(transactionManager="txManager", defaultRollback=true)
public class MyTest {
@Resource
FooDAO fooDAO;
@Test
public void testRegisterWorker() {
fooDAO.callA("")
}
}
我本来希望这条记录根本不会插入到数据库中。但是我看到该行实际上已插入数据库。我确实使用 Oracle 数据库,所以我认为自动提交默认设置为 true(我认为)。但是spring事务标签不应该覆盖它们吗?
谁能告诉我这里出了什么问题?
【问题讨论】: