Spring/JTA/JPA DAO integration test doesn't rollback?

前端 未结 2 790
逝去的感伤
逝去的感伤 2021-01-19 06:28

My DAO integration tests are failing because entities created during the tests are still in the database at the start of the next test. The exact same behavior is seen from

相关标签:
2条回答
  • I think you will need to go through the logs in details. It could be that the rollbacks you are seeing are working, except that something else has executed a commit first. I also cannot see anything in your code which indicates automated rollback. And that it should occur at the end of each test. If you are depending on a timeout based rollback it could be that the second test is running before the timeout occurs, therefore it sees the data before it is rolled back.

    Many options here there is :-)

    0 讨论(0)
  • 2021-01-19 07:31

    It turned out that my C3P0 JDBC data source was not XA aware and was therefore not participating in the transaction. Why I did not get an error, nor a warning in the log file, I do not know. Nonetheless, the reason you cannot use an XA aware data source is explained very nicely here. Note that the data source does not need to be XA capable...just XA aware.

    Replacing the C3P0 data source with the following one solved the problem.

    <bean id="myappJTANonXADataSource" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean">
            <property name="uniqueResourceName" value="myappDatabase" />
            <property name="driverClassName" value="$DS{hibernate.connection.driver_class}" />
            <property name="url" value="$DS{hibernate.connection.url}" />
            <property name="user" value="$DS{hibernate.connection.username}" />
            <property name="password" value="$DS{hibernate.connection.password}" />
            <property name="maxPoolSize" value="20" />
            <property name="reapTimeout" value="300" />
    </bean>
    
    0 讨论(0)
提交回复
热议问题