Announcement Announcement Module
Collapse
No announcement yet.
Transaction propagation between two tx:advice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction propagation between two tx:advice

    Hi all, I have a batch with spring and hibernate.
    I use declarative description for transaction.

    I've noticed that you can define multiple transaction advice as described here:
    http://static.springsource.org/sprin...rative-diff-tx

    Is the transaction propagation is possible between two advices?
    I think no because I have two advices one for services one for DAO with the same transaction manager:
    Code:
    <tx:advice id="daoTxAdvice" transaction-manager="transactionManager">
    <tx:advice id="serviceTxAdvice" transaction-manager="transactionManager">
    <aop:advisor  advice-ref="serviceTxAdvice" pointcut="...Services..."/>
    <aop:advisor  advice-ref="daoTxAdvice" pointcut="...DAOs..."/>
    and propagation between service and DAO doesn't work.

    instead if I use the same aop advisor and the same transaction advice, propagation works.

    thx for your help

  • #2
    There should be nothing preventing you from doing so as long as you use the same transaction manager instance as that is what is driving the transaction. However in general only your service layer should be transactional and not your data-access layer.

    Comment


    • #3
      indeed, there was a problem with my conditions in the pointcuts.
      with a simple declaration, it works:
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:aop="http://www.springframework.org/schema/aop"
              xmlns:tx="http://www.springframework.org/schema/tx"
              xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
      
      	<tx:advice id="serviceTxAdvice" transaction-manager="transactionManager">
          <tx:attributes>
              <tx:method name="*" propagation="REQUIRES_NEW" isolation="READ_COMMITTED" />
          </tx:attributes>
      </tx:advice>
          <tx:advice id="daoTxAdvice" transaction-manager="transactionManager">
              <tx:attributes>
                  <tx:method name="*" propagation="MANDATORY" isolation="READ_COMMITTED" />
              </tx:attributes>
          </tx:advice>
          <aop:config>
              <aop:advisor advice-ref="serviceTxAdvice" pointcut="( execution(* XXX.service..*.*(..))) " />
              <aop:advisor advice-ref="daoTxAdvice" pointcut="execution(* XXX.dao.due.*DAO+.*(..)) " />
          </aop:config>
          <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
              <property name="sessionFactory" ref="sessionFactory" />
          </bean>
      </beans>
      thx!

      Comment

      Working...
      X