Atomikos Forum

Rollback issue with atomikos,jndi and spring

Hi

Transactions with rollback happening perfectly when using Spring.

But when trying to use it with JNDI it commits every execution and not rolling back.

<Listener className="com.atomikos.tomcat.AtomikosLifecycleListener" />

Here are the changes added in server.xml
<Resource name="jdbc/mssql" auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean" factory="com.atomikos.tomcat.BeanFactory" uniqueResourceName="jdbc/mssql" xaDataSourceClassName="com.microsoft.sqlserver.jdbc.SQLServerXADataSource" xaProperties.databaseName="mssqldb" xaProperties.serverName="servername" xaProperties.user="user" xaProperties.password="pwd" poolSize="5" borrowConnectionTimeout="60"/>

    <Resource name="jdbc/mysql" auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean" factory="com.atomikos.tomcat.BeanFactory" uniqueResourceName="jdbc/mysql" xaDataSourceClassName="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" xaProperties.databaseName="mysqldb" xaProperties.serverName="servername" xaProperties.port="3306" xaProperties.user="user" xaProperties.password="pwd" xaProperties.url="url" xaProperties.pinGlobalTxToPhysicalConnection="true" poolSize="5" borrowConnectionTimeout="60"/>

context.xml:

<Transaction factory="com.atomikos.icatch.jta.UserTransactionFactory" />

<ResourceLink global="jdbc/mssql" name="jdbc/mssql" type="com.atomikos.jdbc.AtomikosDataSourceBean"/>
    <ResourceLink global="jdbc/mysql" name="jdbc/mysql" type="com.atomikos.jdbc.AtomikosDataSourceBean"/>

spring config file

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" " http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans> 
    <bean id="mssqlDS" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/mssql" />
    </bean>

    <bean id="mysqlDS" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/mysql" />
    </bean>
     
<bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp" 
  init-method="init" destroy-method="shutdownForce">
    <constructor-arg>     
        <props>
            <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory
            </prop>
        </props>
    </constructor-arg>   
</bean>


  <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close" depends-on="userTransactionService">
        <description>UserTransactionManager</description> 
        <property name="forceShutdown"> 
            <value>true</value> 
        </property> 
    </bean> 
   
     
  <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService">
        <description>UserTransactionImp</description> 
        <property name="transactionTimeout" value="300"/> 
    </bean> 
 
 
    <bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="userTransactionService"> 
        <description>JtaTransactionManager</description> 
        <property name="transactionManager"> 
            <ref bean="atomikosTransactionManager" /> 
        </property> 
        <property name="userTransaction"> 
            <ref bean="atomikosUserTransaction" /> 
        </property> 
    </bean> 
   
    <bean id="transactionProxyFactoryBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> 
        <property name="transactionManager"> 
            <ref bean="springTransactionManager" /> 
        </property> 
        <property name="transactionAttributes"> 
            <props> 
                <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop> 
            </props> 
        </property> 
    </bean> 
   
    <bean id="mysqlDao" class="com.jta.MysqlDaoImpl"> 
        <property name="dataSource" ref="mysqlDS" /> 
    </bean>
     
    <bean id="mssqlDao" class="com.jta.MssqlDaoImpl"> 
        <property name="dataSource" ref="mssqlDS" /> 
    </bean>
     
    <bean id="TxManager" class="com.jta.TxManagerImpl"> 
        <property name="mysqlDao" ref="mysqlDao" /> 
        <property name="mssqlDao" ref="mssqlDao" /> 
    </bean>
     
    <bean id="TxManagerProxy" parent="transactionProxyFactoryBean"> 
        <property name="target"> 
            <ref bean="TxManager" /> 
        </property> 
    </bean>
     
</beans> 

Anybody has idea of what is the problem and what needs to be changed here?

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

I've done the configuration file changes properly and its working fine now.

But getting the following exception during tomcat startup.
Any idea on this? Is this harmful?

com.microsoft.sqlserver.jdbc.SQLServerException: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectionCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendCommit(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.commit(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:157)
    at $Proxy3.commit(Unknown Source)
    at com.manthan.promax.report.UsageProcess.transferMasterData(UsageProcess.java:3853)
    at com.manthan.promax.db.ApplicationConfig.setApplicationParameters(ApplicationConfig.java:794)
    at org.fourfive.servlets.BoosterStarter1.call(BoosterStarter1.java:363)
    at org.fourfive.servlets.BoosterStarter1.init(BoosterStarter1.java:244)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4420)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4733)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)


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

Found that this issue occurs when AtomikosDataSourceBean is used for XA Transactions as well as normal DB Operations. Normal DB Operation is performed and then this exception is thrown.

Any fix or workaround for this?

thanks
Caroline
Caroline Sherly Send private email
Friday, May 04, 2012
 
 
Hi Caroline,

I configure two data sources in a case like this. One data source with Atomikos beans + XA driver and one data source without XA driver.

Regards,
Rainer
Rainer Wallscheid Send private email
Friday, May 04, 2012
 
 
Hi Rainer,

Yes I've tried that case before and it has no issues.

Only when I try to use the same datasource is used then it causes this problem.

I'm asking is there any fix for this?

thanks,
Caroline
Caroline Sherly Send private email
Monday, May 07, 2012
 
 
Hi Caroline,

I am facing similar situation and some of the transactions are not rollback. Specifically in the case where Atomikos is unable to grow connection pool due to DB restrictions on processes. I was debating if I should add
<!--            when close is called,          should we force transactions to terminate or not?    -->    <property name="forceShutdown" value="false" />

to the UserTransactionManager configuration. Can you please share how did you fix the issue in your environment? I have following settings


 <bean id="AtomikosUserTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp" init-method="init" destroy-method="shutdownForce">^M
        <constructor-arg>^M
            <props>^M
                <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>^M
                <prop key="com.atomikos.icatch.max_actives">200</prop>^M
                <prop key="com.atomikos.icatch.max_timeout">11600000</prop>^M
                <prop key="com.atomikos.icatch.log_base_dir">/home/asynch_batch/batch/data</prop>^M
                <prop key="com.atomikos.icatch.console_file_name">transaction.log</prop>^M
                <prop key="com.atomikos.icatch.console_file_count">10</prop>^M
                <prop key="com.atomikos.icatch.console_file_limit">10485760</prop>^M
                <prop key="com.atomikos.icatch.output_dir">/home/asynch_batch/batch/logs</prop>^M
                <prop key="com.atomikos.icatch.enable_logging">false</prop>^M
                <prop key="com.atomikos.icatch.console_log_level">WARN</prop>^M
            </props>^M
        </constructor-arg>^M
        <!-- Enable this for graphical transaction debugging -->^M
        <!-- property name="initialLogAdministrators">^M
            <list>^M
                <ref bean="AtomikosLocalLogAdministrator"/>^M
            </list>^M
        </property-->^M
    </bean>^M
    <bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close" depends-on="AtomikosUserTransactionService">^M
        <property name="forceShutdown" value="false" />^M
    </bean>^M
    <bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="AtomikosUserTransactionService">^M
        <property name="transactionTimeout" value="300" />^M
    </bean>^M
        <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">^M
                <property name="transactionManager" ref="AtomikosTransactionManager"/>^M
                <property name="userTransaction" ref="AtomikosUserTransaction"/>^M
        <property name="globalRollbackOnParticipationFailure" value="false" />^M
        </bean>^M



My application starts one transaction and calls three different APIs that make changes on two DBs. If the first API is successful but the second one fails then I still see the data persisted by first API.

I also saw another property globalRollbackOnParticipationFailure. I am not sure what it does and searching through the documentation.

Thanks
Munish
Munish Send private email
Tuesday, June 05, 2012
 
 

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

Other recent topics Other recent topics