PDA

View Full Version : AbstractTransactionalDataSourceSpringContextTests RollBack


snarasim
Mar 1st, 2006, 05:19 PM
I wrote a test that derices from AbstractTransactionalDataSourceSpringContextTests and in the test i made a few insertions into the database. I expected the data to be rolled back after the test run but my mysql db still has the data that i inserted from the test.

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource">
<ref local="migrationDB"/>
</property>
</bean>

<!--JDBC Config -->
<bean id="migrationDB" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/dashboard</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>

what am i doing wrong?

bpolka
Mar 1st, 2006, 06:13 PM
what mysql version are you using? You need innoDB variety for this to work.

snarasim
Mar 1st, 2006, 06:21 PM
i also tried the following options in my test nothing seems to work

protected void onSetUpInTransaction() throws Exception {
super.onSetUpInTransaction();
setDefaultRollback(true);
dao.setJdbcTemplate(jdbcTemplate);
BasicDataSource dataSource = (BasicDataSource) dao.getDataSource();
dataSource.setDefaultAutoCommit(false);
DataSourceUtils.getConnection(dataSource).setAutoC ommit(false);
}

snarasim
Mar 2nd, 2006, 04:46 PM
Has any one tried made this work before with mysql?

Costin Leau
Mar 3rd, 2006, 05:11 AM
Yes and it works. You have to define a transaction manager for your datasource in order to work otherwise there are not transactions to be rolledback. Turn on logging and you'll see what happens when the test is executed. Search the forum also since this topic has been discussed several times.