Announcement Announcement Module
Collapse
No announcement yet.
AbstractTransactionalDataSourceSpringContextTests RollBack Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractTransactionalDataSourceSpringContextTests RollBack

    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.DataSou rceTransactionManager">
    <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?

  • #2
    what mysql version are you using? You need innoDB variety for this to work.

    Comment


    • #3
      I am using mysql 5.0.18 and its InnoDB

      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);
      }

      Comment


      • #4
        AbstractTransactionalDataSourceSpringContextTests? ?

        Has any one tried made this work before with mysql?

        Comment


        • #5
          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.

          Comment

          Working...
          X