Atomikos Forum

Sprint Test / JPA / Hibernate -- Rollback not happening

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 both MySQL 5 and H2.

The test classes are annotated with:
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/testPersist-applicationContext.xml" })

The transaction bean configuration in the test application context is as follows:

<tx:annotation-driven />

<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="atomikosTransactionManager" />
    <property name="userTransaction" ref="atomikosUserTransaction" />
</bean>

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
    <property name="forceShutdown" value="false" />
</bean>

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
    <property name="transactionTimeout" value="300" />
</bean>

The entity manager is configured as follows:

<bean id="myappTestLocalEmf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="myapp" />
    <property name="persistenceUnitPostProcessors">
        <bean                class="com.myapp.core.persist.util.JtaPersistenceUnitPostProcessor">
        <property name="jtaDataSource" ref="myappPersistTestJdbcDataSource" />
        </bean>
    </property>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="false" />
            <property name="database" value="$DS{hibernate.database}" />
            <property name="databasePlatform" value="$DS{hibernate.dialect}" />
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
            </prop>
            <prop key="hibernate.format_sql">true"</prop>
            <prop key="hibernate.use_sql_comments">true</prop>
            </props>
    </property>
</bean>

<context:annotation-config />

Everything in the log files seem to be fine...I can see messages from Spring about rollback and from Atomikos about rollback as well.

Yet the inserted data remains!  Any clues?
Dave Vree Send private email
Sunday, June 27, 2010
 
 
Did you configure the datasource as an AtomikosDataSourceBean?

HTH
Guy Pardon Send private email
Sunday, June 27, 2010
 
 
No - I used the C3PO, non-XA, pooled data source, which, thanks to you, I found will not work with Atomikos as explained here:

http://www.atomikos.com/Documentation/ExternalConnectionPool
Dave Vree Send private email
Tuesday, June 29, 2010
 
 
Correct, C3PO does not know Atomikos nor XA so it can't enlist in the JTA transaction. There is nothing we can do about that...
Guy Pardon Send private email
Monday, July 05, 2010
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics