Spring @Transactional:报告但未实际执行的回滚信息
我已将我的测试类注释如下:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:WebContent/WEB-INF/applicationContext.xml", "file:WebContent/WEB-INF/context-aspects.xml"})
@Transactional
public class MyTest {
}
但是,在执行测试时,测试数据库突然充满了值,尽管启用了 @Transactional 并且我可以在日志中读取以下内容:
INFO: Began transaction (4): transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@669aa3f3]; rollback [true]
07.04.2011 23:57:33 org.springframework.test.context.transaction.TransactionalTestExecutionListener endTransaction
INFO: Rolled back transaction after test execution for test context ...
任何想法为什么测试用例后的实际回滚是没有执行?
更新:如果我使用HSQLDB,我就不会遇到这些问题 - 那么这是mysql的问题吗?
I have annotated my test classes as follows:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:WebContent/WEB-INF/applicationContext.xml", "file:WebContent/WEB-INF/context-aspects.xml"})
@Transactional
public class MyTest {
}
However, when executing tests, the test database is suddenly filled with values, although @Transactional is enabled and I can read the following in the log:
INFO: Began transaction (4): transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@669aa3f3]; rollback [true]
07.04.2011 23:57:33 org.springframework.test.context.transaction.TransactionalTestExecutionListener endTransaction
INFO: Rolled back transaction after test execution for test context ...
Any ideas why the actual rollback after the test case is not performed?
Update: If I am using HSQLDB, I don't have these problems - so is it a problem of mysql?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的你是对的。
检查您是否使用了正确的方言(使用 Hibernate 时:org.hibernate.dialect.MySQL5InnoDBDialect),并且您应该监视发送到数据库的语句。
Yes you are right.
Check that you use the right dialect (when using Hibernate: org.hibernate.dialect.MySQL5InnoDBDialect), and may you should monitor the statements that been send to the database.
我终于可以解决这个问题了。 Hibernate 生成的 MyISAM 表显然没有事务支持。这是由于配置了错误的休眠方言造成的。我用过
org.hibernate.dialect.MySQL5Dialect,但 org.hibernate.dialect.MySQL5InnoDBDialect 是必需的。
I could finally solve the problem. Hibernate was generating MyISAM tables which apparently have no Transaction support. This was due to a wrong hibernate dialect configured. I used
org.hibernate.dialect.MySQL5Dialect, but org.hibernate.dialect.MySQL5InnoDBDialect is required.