Spring with multiple transaction managers

zt4PX
Here is repost of http://stackoverflow.com/questions/4423125/spring-is-it-possible-to-use-multiple-transaction-managers-in-the-same-applica question.

Here is applicationContext.xml config part:

<bean id="transactionManager1" class="org.springframework.orm.jpa.JpaTransactionManager"> 
  <property name="entityManagerFactory" ref="entityManagerFactory1" /> 
  <qualifier value="account"/> 
</bean>

<bean id="transactionManager2" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactory2" /> 
  <qualifier value="businessData"/> 
</bean>

and code using:

public class TransactionalService {

    @Transactional("account")
    public void setSomethingInAccount() { ... }

    @Transactional("businessData")
    public void doSomethingInBusinessData() { ... }
}

So, as you see we can simply use several connections with transaction management in Spring application.

See also,
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#tx-multiple-tx-mgrs-with-attransactional
Enjoy!