Announcement Announcement Module
Collapse
No announcement yet.
ThrowsAdvice initiate rollback Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ThrowsAdvice initiate rollback

    Can I create a class which implements ThrowsAdvice that can instantiate a transaction rollback?

    For example, if the code throws a MySystemException and normally I do not want the transaction to rollback, but once in a while I do.

    I would like to create a ThrowsAdvice which could do something like this:

    public class ExceptionAdvice implements ThrowsAdvice {
    public void afterThrowing(Exception ex) throws Throwable {
    if ( it is really bad) {
    dataSourceTransactionManager.rollback(status);
    }
    throw ex;
    }
    }

    In EJB, if I wanted to instantiate a rollback I used to do this:
    getSessionContext().setRollbackOnly();




    Here is part of my bean:

    <bean id="abstractTransactionProxy" abstract="true" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="update*">PROPAGATION_REQUIRED,+MySystemExcept ion</prop>
    </props>
    </property>
    </bean>


    Thanks for any help.

  • #2
    TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly()

    Comment


    • #3
      That worked.
      Thanks for your help.

      Comment

      Working...
      X