I try to fill a Database Table with DBUnit within a Spring Transactional Test. The datasource is a TransactionAwareDataSourceProxy. So i would thing giving this source to DBUnit and than filling the Table should be visible for the jdbcTemplate query afterwards?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"many contexts"})
@TransactionConfiguration(transactionManager = "transactionManager")
@Transactional
public class DBTest {
@Autowired(required = true)
TransactionAwareDataSourceProxy dataSource;
private JdbcTemplate jdbcTemplate;
@Autowired(required = true)
public void setJdbcTemplate(TransactionAwareDataSourceProxy dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Autowired(required = true)
SessionFactory sessionFactory;
@Test
@Transactional
public void test() throws Exception {
IDatabaseConnection dbConn = new DatabaseDataSourceConnection(dataSource);
DatabaseOperation.CLEAN_INSERT.execute(dbConn, new XmlDataSet(ClassLoader.getSystemResourceAsStream("TABLE.xml")));
System.out.println("Es wurden gefunden : " + this.jdbcTemplate.queryForInt("select count(*) from TABLE"));
System.out.println("blaaa");
}
The query always returns 0. What am i missing?
I've seen this happen when dbUnit and the production app share the same transaction/datasource. What "fixes" it is a "flush", either by manually invoking a flush in the test or using a separate transaction or db connection (so dbUnit's changes flush).
一种解决方案。...我将DBUnit版本从2.4.9更改为2.5.2,现在一切正常。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.