Announcement Announcement Module
Collapse
No announcement yet.
Atomikos doesn't roll back. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Atomikos doesn't roll back.

    Hello,

    I think I configured my web app's transactions to be managed by Atomikos and Spring but what I expected to happen isn't working. Whenever an exception (any kind of exception) occurs in my service layer (which is called 'manager' in my application) I want a rollback to happen, but this isn't working. Could you guys check out my xml-files & classes to see what I'm doing wrong here?


    this is my application context:
    Code:
      <bean id="loginControllerImpl" class="com.comp.proj.webconsole.controller.LoginControllerImpl"
              scope="singleton">
            <constructor-arg ref="adminWebDbManager" index="0"/>
        </bean>
    
        <bean id="userControllerImpl" class="com.comp.proj.webconsole.controller.UserControllerImpl" scope="singleton">
            <constructor-arg ref="adminWebDbManager" index="0"/>
        </bean>
    
        <bean id="logControllerImpl" class="com.comp.proj.webconsole.controller.LogControllerImpl" scope="singleton">
            <constructor-arg ref="webAdminAuditDbManager" index="0"/>
        </bean>
    
        <bean id="practiceControllerImpl" class="com.comp.proj.webconsole.controller.PracticeController" scope="singleton">
            <property name="practiceDbManager" ref="practiceDbManager"/>
        </bean>
    
        <!-- Handlers -->
    
        <bean id="myLoginRedirectHandler" class="com.comp.proj.webconsole.util.MyLoginRedirectHandler"/>
    
    
        <!--TF DB -->
       <bean id="tf_database" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
            <property name="uniqueResourceName" value="XADBMS"/>
            <property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"/>
            <property name="xaProperties">
                <props>
                    <prop key="url">jdbc:mysql://localhost:3306/db1</prop>
                    <prop key="user">dummy</prop>
                    <prop key="password">dummy</prop>
                </props>
            </property>
            <property name="poolSize" value="3"/>
        </bean>
    
    
        <bean id="tf_sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="mappingDirectoryLocations">
                <list>
                    <value>classpath:*tf_hibernate</value>
                </list>
            </property>
            <property name="dataSource" ref="tf_database"/>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.transaction.factory_class">
                        com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
                    </prop>
                    <prop key="hibernate.transaction.manager_lookup_class">
                        com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
                    </prop>
                </props>
            </property>
        </bean>
    
        <bean id="tf_hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory" ref="tf_sessionFactory"/>
        </bean>
    
        <bean id="atomikosTransactionManager" init-method="init" destroy-method="close" class="com.atomikos.icatch.jta.UserTransactionManager">
            <property name="forceShutdown" value="true"/>
        </bean>
    
        <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" >
            <property name="transactionTimeout" value="300"/>
        </bean>
    
    
        <bean id="jtaTransactionManager"
              class="org.springframework.transaction.jta.JtaTransactionManager">
            <property name="transactionManager" ref="atomikosTransactionManager" />
            <property name="userTransaction" ref="atomikosUserTransaction" />
        </bean>
    
    
        <bean id="practiceDbManager" class="com.comp.proj.webconsole.dbmanager.PracticeDbManager" scope="singleton">
            <property name="tf_practiceDao" ref="tf_practiceDao"/>
        </bean>
    
        <bean id="practice1DbManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager" ref="jtaTransactionManager"/>
            <property name="target" ref="practiceDbManager"/>
            <property name="transactionAttributes">
                <props>
                    <prop key="*">PROPAGATION_REQUIRED, -EXCEPTION</prop>
                </props>
            </property>
        </bean>
    I'm trying to rollback everything what happens in "practiceDbManager" when any exception occurs in this manager.

    jta.properties
    Code:
    com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
    com.atomikos.icatch.console_file_name = tm.out
    com.atomikos.icatch.log_base_name = tmlog
    com.atomikos.icatch.tm_unique_name = com.atomikos.spring.jdbc.tm
    com.atomikos.icatch.console_log_level = INFO
    com.atomikos.icatch.serial_jta_transactions=false
    practiceDbManager.java
    Code:
    package com.comp.proj.webconsole.dbmanager;
    public class PracticeDbManager {
        Tf_PracticeDao tf_practiceDao;
        public Tf_PracticeDao getTf_practiceDao() {
            return tf_practiceDao;
        }
        public void setTf_practiceDao(Tf_PracticeDao tf_practiceDao) {
            this.tf_practiceDao = tf_practiceDao;
        }
        public Boolean createPractice(TfPracticeDetails tfPracticeDetails){
            //as of the moment multiple databases are communicated with, this method will expand.
            //TODO: place username validation in vtype instead of in the manager.
            if(!tf_practiceDao.practiceNameExists(tfPracticeDetails.getPracticeName()))
                if(tf_practiceDao.createPractice(tfPracticeDetails)){
                    Integer.parseInt("no integer so this should give an error which should cause the previous transaction to rollback.");
                        return true;
                }
                else
                    return false;
            else
                return false;
        }
    
        public Boolean practiceNameExists(String practiceName)
        {
            return tf_practiceDao.practiceNameExists(practiceName);
        }
    }
    There's another database as well (of which the config is pretty much the same as the first one) so what I'm trying to achieve in the end with atomikos is a two-phase commit or rollback.
    Does anyone see what I'm doing wrong here? I've been struggling with it for 3 days now and I'm starting to get out of ideas.

    Thanks,
    Simon
    Last edited by Duffman-; May 7th, 2010, 11:01 AM.

  • #2
    Is there no one who can help?

    Comment


    • #3
      You don't declare any exceptions are throw in your manager which means that your dao's are either eating them or they are only throwing runtimeexceptions. You don't need to have the exception declaration on your proxy in this case (the default is to rollback on any runtimeexception).

      Note however that your controller is wired up to your db manager, not the proxied version of this class...which is why you aren't getting any transaction management.

      Comment


      • #4
        Anybody found the solution for this problem? I am facing the same issue :-(

        Comment

        Working...
        X