【发布时间】:2017-03-20 15:14:45
【问题描述】:
我有一个 Spring / JDBC 应用程序,它严重依赖 MySQL 回滚来进行单元测试。我发现如果我在这些事务中执行某些 DDL 操作 - 即使是在临时表上 - 即使在正常的 DML 语句上,回滚也会失败。例如:
@Test
@Rollback(true)
public void testRollbackProblem() {
template.update("create temporary table foo (id INTEGER )");
template.update("update forms set form_name = 'blah' where form_id = 1412");
template.update("alter table foo add (name text)");
}
此测试完成后,中间语句将被持久化,不会回滚。有没有办法防止这种情况?也许某些参数传递给alter 语句?
【问题讨论】: