开发者

Spring @Transactional: Rollback information reported but not actually performed

开发者 https://www.devze.com 2023-02-22 17:21 出处:网络
I have annotated my test classes as follows: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={\"file:WebContent/WEB-INF/applicationContext.xml\", \"file:WebContent/WEB-INF/con

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 perf开发者_开发百科ormed?

Update: If I am using HSQLDB, I don't have these problems - so is it a problem of mysql?


Update: If I am using HSQLDB, I don't have these problems - so is it a problem of mysql?

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消