title: Spring multiple transaction managers, single transaction
body: <p>I have a complex situation where I have to use 2 different databases, there for I use 2 different transaction managers. Is there a way in Spring to link these transaction managers to work in a single transaction ? In case of an exception on the second dataSource changes on the first should be rolled-back.</p>
  
  <pre><code>&lt;bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
  abstract="true"&gt;
   &lt;property name="transactionManager" ref="transactionManager" /&gt;
   &lt;property name="transactionAttributes"&gt;
    &lt;props&gt;
      &lt;prop key="insert*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
      &lt;prop key="update*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
      &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
      &lt;prop key="remove*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
      &lt;prop key="*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;
    &lt;/props&gt;
   &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
   &lt;property name="driverClassName" value="oracle.jdbc.OracleDriver" /&gt;
   &lt;property name="url" value="jdbc:oracle:thin:@dummyHost:1521:dummySID" /&gt;
   &lt;property name="username" value="owner" /&gt;
   &lt;property name="password" value="password" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
   &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
   &lt;property name="driverClassName" value="oracle.jdbc.OracleDriver" /&gt;
   &lt;property name="url" value="jdbc:oracle:thin:@dummyHost2:1521:dummySID2" /&gt;
   &lt;property name="username" value="owner" /&gt;
   &lt;property name="password" value="password" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
   &lt;property name="dataSource" ref="dataSource2" /&gt;
  &lt;/bean&gt;
  </code></pre>