takimafr / spring-dbunit

DBUnit support for Spring
Apache License 2.0
40 stars 19 forks source link

Rollback not working with postgresql 9.1 #25

Open regis-leray opened 11 years ago

regis-leray commented 11 years ago

It try to use the rollback feature but it doesnt seems to work.

im using

<springframework.version>3.2.1.RELEASE</springframework.version>
 <hibernate.version>4.2.1.Final</hibernate.version>
 <spring-data-jpa.version>1.3.1.RELEASE</spring-data-jpa.version>
 <spring-dbunit.version>1.1.12</spring-dbunit.version>

Here my log

https://gist.github.com/regis-leray/f5fbd8aa4f6e5e475057

In my junit test

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext-int.xml")
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
        TransactionalTestExecutionListener.class,
        RollbackTransactionalDataSetTestExecutionListener.class })
@TransactionConfiguration(defaultRollback = true)
@Transactional
@DataSet(locations = {"dataset_configuration.xml"}, dbType = DBType.POSTGRESQL)
public class ITConfigurationServiceImplTest {

    @Autowired
    ConfigurationService configurationService;

    @Test
    public void shouldSaveConfiguration(){

        ConfigurationTO to = new ConfigurationTO();
        to.setKey("newKey");
        to.setValue("newValue");

        configurationService.saveConfiguration(to);
        to = configurationService.getConfiguration("newKey");

        assertNotNull(to);
        assertEquals(to.getValue(), "newValue");

    }
}

in My applicationContext-datasource xml file

<!-- Database configuration ==================================================================================== -->
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

        <property name="dataSource" ref="dataSource" />
        <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />

        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>

        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">${app.db_hibernate_dialect}</prop>
                <prop key="hibernate.show_sql">${app.showSql:false}</prop>
                <prop key="hibernate.hbm2ddl.auto">${app.hbm2ddl:validate}</prop>
                <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache:true}</prop>
                <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache:true}</prop>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                <prop key="net.sf.ehcache.configurationResourceName">ehcache-${app.ehcachemode}.xml</prop>

            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
        <property name="driverClassName" value="${app.db_driver}" />
        <property name="url" value="${app.db_url}" />
        <property name="username" value="${app.db_username}" />
        <property name="password" value="${app.db_password}" />
        <property name="maxWait" value="${datasource.maxWait:30000}" />
        <!-- The initial number of connections that are created when the pool is started -->
        <property name="initialSize" value="${datasource.initialSize:10}" />
        <!-- The maximum number of active connections that can be allocated from this pool at the same time. -->
        <property name="maxActive"   value="${datasource.maxActive:20}" />
        <!-- The maximum number of connections that should be kept in the pool at all times -->
        <property name="maxIdle"     value="${datasource.maxIdle:20}" />
    </bean>

Also the transaction management is working well my test shouldSaveConfiguration() doesnt create a record in the database, but the dbunit dataset is not remove from the database table.

If i have time , l will run the unit test of spring dbunit with postgres 9 with the rollback feature

PS:

I find a way to resolve that with the dbunit feature

@DataSet(locations = {"dataset_configuration.xml"}, dbType = DBType.POSTGRESQL), tearDownOperation = DBOperation.DELETE_ALL)
rsertelon commented 9 years ago

@regis-leray Is this issue still relevant?

regis-leray commented 9 years ago

The rollback doesnt work, my fix is just a hack.

rsertelon commented 9 years ago

Have you tried with the latest version of Spring DBUnit? (1.3.0)

rsertelon commented 9 years ago

Hmm don't bother testing with another version. It seems that the way you fixed the problem should be done in the background for you. The thing is that if you don't specify the tearDownOperation, nothing will be done.

rsertelon commented 9 years ago

@regis-leray Could you test the version given by branch fix-25 (link above this comment)?

I think I've nailed the problem, but as I didn't write the whole library, I might have missed something. I don't have anything to test with me :)

rsertelon commented 9 years ago

@regis-leray Have you had time to try with the fix I've pushed?

regis-leray commented 9 years ago

sorry i dont use anymore this library. And i dont have the project setup on my machine. But you can create a integration test like i did. With a simple object and in memory database

Implements the same as my example in unit test

https://github.com/excilys/spring-dbunit/blob/master/spring-dbunit-test/src/test/java/com/excilys/ebi/spring/dbunit/test/MyEntityDaoH2Test.java

rsertelon commented 9 years ago

Will do, thanks for the test case!

sandrocsimas commented 9 years ago

@rsertelon, can you tell me when you will release a new version with this bug fix? I have the same problem in oracle database. Did you test the code of branch fix-25?