Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollback not working with postgresql 9.1 #25

Open
regis-leray opened this issue May 12, 2013 · 9 comments
Open

Rollback not working with postgresql 9.1 #25

regis-leray opened this issue May 12, 2013 · 9 comments
Milestone

Comments

@regis-leray
Copy link

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
Copy link
Contributor

@regis-leray Is this issue still relevant?

@regis-leray
Copy link
Author

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

@rsertelon
Copy link
Contributor

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

@rsertelon
Copy link
Contributor

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
Copy link
Contributor

@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 rsertelon modified the milestone: 1.4.1 Oct 2, 2014
@rsertelon
Copy link
Contributor

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

@regis-leray
Copy link
Author

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
Copy link
Contributor

Will do, thanks for the test case!

@sandrocsimas
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants