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?
Kind of solution.... I changed DBUnit version from 2.4.9 to 2.5.2 now everything works fine.