Atomikos Forum

Atomikos + Spring - not rolling back

Hi
I have problem with Transaction not rolling back while using Spring.

The spring configuration file is shown below.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:task="http://www.springframework.org/schema/task"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context-3.0.xsd
                          http://www.springframework.org/schema/tx
                          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                          http://www.springframework.org/schema/task
                          http://www.springframework.org/schema/task/spring-task-3.0.xsd">

<!-- Use an Atomikos DataSource to access the DB transactionally -->
<bean id="mysqldatasource"
    class=" com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
    <property name="xaDataSourceClassName"><value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value></property>
    <property name="xaProperties">
        <props>
            <prop key="user">root</prop>
            <prop key="password">root</prop>
            <prop key="serverName">mss181</prop>
            <prop key="databaseName">javatest</prop>
            <prop key="url">jdbc:mysql://localhost:3306/javatest</prop>
            <prop key="pinGlobalTxToPhysicalConnection">true</prop>
        </props>
    </property>
    <property name="uniqueResourceName"><value>javatest</value></property>    
    <property name="poolSize"><value>5</value></property>
    <property name="borrowConnectionTimeout"><value>60</value></property>

</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
    <!--  when close is called, should we force transactions to terminate or not? -->
    <property name="forceShutdown"><value>true</value></property>
</bean>

<!-- Also use Atomikos UserTransactionImp, needed to configure Spring  -->
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
    <property name="transactionTimeout"><value>300</value></property>
</bean>

<!-- Configure the Spring framework to use JTA transactions from Atomikos -->
<bean id="JTATransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager"><ref bean="atomikosTransactionManager"  /></property>
    <property name="userTransaction"><ref bean="atomikosUserTransaction"  /></property>
</bean>

<!-- Configure the bank to use our datasource -->
<bean id="carolineTarget" class= "xa.test.AtomikosMsSqlMySql">
    <property name="mysqlDataSource"><ref bean="mysqldatasource" /></property>
    <!-- property name="mssqldatasource"><ref bean="mssqldatasource" /></property> -->
</bean>

<!-- Configure Spring to insert JTA transaction logic for all methods -->
<bean id="caroline" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="JTATransactionManager" /></property>
    <property name="target"><ref bean="carolineTarget"  /></property>
    <property name="transactionAttributes">
        <props>
            <prop key="*">PROPAGATION_REQUIRED, -Exception</prop>
        </props>
    </property>
</bean>


And my java code is:
AtomikosMsSqlMySql atom = (AtomikosMsSqlMySql) SpringApplicationContextUtils.getApplicationContext().getBean("caroline");
            
atom.checkTables();
atom.executeSelect ();
atom.executeInsert();
atom.executeDelete();
atom.executeWrongInsert();

My aim is after executeWrongInsert is called, whatever is inserted using executeInsert and deleted using executeDelete should be rolled back. That is not happening.

In the log it says

Apr 23, 2012 1:42:13 PM com.atomikos.diagnostics.Slf4jConsole println
INFO: registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@ec5f41de ) for transaction 172.20.1.93.tm0000600013
Apr 23, 2012 1:42:13 PM com.atomikos.diagnostics.Slf4jConsole println
INFO: XAResource.end ( 3137322E32302E312E39332E746D30303030363030303133:3137322E32302E312E39332E746D35 , XAResource.TMSUCCESS ) on resource javatest represented by XAResource instance com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection@cc1016
Apr 23, 2012 1:42:13 PM com.atomikos.diagnostics.Slf4jConsole println
INFO: XAResource.rollback ( 3137322E32302E312E39332E746D30303030363030303133:3137322E32302E312E39332E746D35 ) on resource javatest represented by XAResource instance com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection@cc1016
Apr 23, 2012 1:42:13 PM com.atomikos.diagnostics.Slf4jConsole println
INFO: rollback() done of transaction 172.20.1.93.tm0000600013

can anyone help me to figure out what the problem and suggest the solution?

thanks,
Caroline
Caroline Sherly Send private email
Monday, April 23, 2012
 
 
Your Spring config specifies each execute method as one transaction. So only the last one is rolled back - i.e. the wrong insert...

HTH
Guy Pardon Send private email
Wednesday, April 25, 2012
 
 
Hello Guy,

thanks for your reply.

Yes I found the problem changed the config file.

Now its working fine for mysql and mssql databases.

thanks,
Caroline
Caroline Sherly Send private email
Wednesday, April 25, 2012
 
 

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

Other recent topics Other recent topics