Results 1 to 2 of 2

Thread: Multiple Transaction manager issue

Hybrid View

  1. #1
    Join Date
    Dec 2006
    Posts
    1

    Default Multiple Transaction manager issue

    I have some doubts regarding the multiple transaction manager issue, I have two spring config file defined two spring configuration manager.

    One file

    Code:
      <tx:advice id="txAdvice" transaction-manager="transactionManager1">
     <bean id="transactionManager1" class="org.springframework.jdbc.DataSourceTransactionManager">
        ...
    
      </bean>
    Another file
    Code:
      <tx:advice id="txAdvice" transaction-manager="transactionManager2">
     <bean id="transactionManager2" class="org.springframework.jdbc.DataSourceTransactionManager">
        ...
    
      </bean>
    Both of them was loaded into spring context, Now I have a service class, I didn't use the qulifier to indicate the transaction manager to use, I am wondering which transaction manager spring will going to use. Randomly pick up one or what?

    Code:
    public class TransactionalService {
    
    @Transactional
    public void setSomething(String name) { ... }
    
    @Transactional
    public void doSomething() { ... }
    
    
    }

  2. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    First off, you have both <tx:advice> definitions with same id. It means that one overrides another. You should use <aop:advisor> in combination with <tx:advice> definition. @Transactional annotation works in combination with <tx:annotation-driven/>.
    If you have multiple transaction managers, use @Transactional("resource1") where <bean id="txManager"...><qualifier value="resource1"/></bean> is defined.
    If you want to know the exact way how Spring determines transaction manager for annotated method, read through TransactionAspectSupport#determineTransactionManag er method.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •