Announcement Announcement Module
Collapse
No announcement yet.
TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly() NOT BEHAVING Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly() NOT BEHAVING

    Hi All:

    TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly() Methos is not behaving properly.

    I am using it in the follwoing manner:

    Code:
    runDL()
    for(App app: appList)
    {
    
    try{
    committoDB(app)
    }
    catch(Exception e)
    { e.printstackTrace();}
    }
    }
    }
    
    
    committoDB(App app)
    {
    
    try{
    if(validation1 == false || validation2 == false)
    throw RunTimeExcpetion();
    else
    {
    daoMethod1;
    daoMethod2;
    }
    }
    
    catch(Exception e)
    {
    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
    }
    
    }
    The problem I am facing is that if appList has say ten Items and if all of them pass validation1 and validation2 i.e. they never enter the catch block with call to "TransactionAspectSupport.currentTransactionStatus ().setRollbackOnly()" then everything is committed properly.


    However, if even one of the ten Items fails validation and enters the catch block with this Line:
    TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly()"

    then everything will be rolled back !!!!!!!!!


    Ideal behaviuor is that only the One Validation Failing Data should be rolled back not all ten of them because methods with pattern "commit*" are defined as "PROPAGATION_REQUIRES_NEW".


    The following is my Definition of Declarative Transaction in the Config XML. Items in RED are more relevant:

    Code:
    	<bean id="serviceDefaultTxnAttSrc_framework" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
    		<property name="properties">
    			<props>
    				<prop key="commit*">PROPAGATION_REQUIRES_NEW</prop>
    				<prop key="*">PROPAGATION_REQUIRED,-framework.gen.SysException+framework.service.ApplicationException</prop>
    			</props>
    		</property>
    	</bean>
    	<bean id="serviceDefaultTxnAttInterceptor_framework" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    		<property name="transactionManager">
    			<ref bean="transactionManager"/>
    		</property>
    		<property name="transactionAttributeSource">
    			<ref bean="serviceDefaultTxnAttSrc_framework"/>
    		</property>
    	</bean>
    	<bean id="serviceDefaultProxyCreator_framework" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    		<property name="interceptorNames">
    			<list>
    				<idref bean="serviceDefaultTxnAttInterceptor_framework"/>
    			</list>
    		</property>
    		<property name="proxyTargetClass">
    			<!-- if the bean are not interface (ie classes), this need to be set to true, if not error will be thrown -->
    			<value>true</value>
    		</property>
    		<property name="beanNames">
    			<list>
    				<!-- add the list of service classes here -->
    				<idref bean="SysParamService"/>
    				<!-- value contains the bean name, wildcard works!! -->
    				<value>*Test*</value>
    				<value>*Service</value>
    			</list>
    		</property>
    	</bean>

    Any help is greatly appreciated.

    Chetan

  • #2
    It looks like you are trying to start a new transaction on an internal method call, this won't work. Have a read of this.
    http://www.springframework.org/docs/...decl-explained

    Comment


    • #3
      In addition to what karldmoore said, what you are wishing for is not possible even if an internal transaction was indeed opened for you.

      The issue is related to DB servers in general, and not specifically to Spring's transaction manager.
      What you want is something like:

      begin transaction
      begin transaction
      do Something
      commit
      begin transaction
      do Something
      rollback
      commit transaction

      This is not possible (at least not on Microsoft SQL Server). When you "rollback" you always rollback the main transaction, not a nested one.

      You can read more about it here:
      http://blogs.microsoft.co.il/blogs/s...nsactions.aspx

      Note that when I wrote this blog post, I still though that it can work, but even my last suggestion there is not working.

      Comment

      Working...
      X