title: Abstract routing datasource with different Databases
body: <p>We have an application where we have implemented Abstract Routing Data source feature in dealing multiple data bases of same type mysql (jdbc:mysql://127.0.0.1:3306/test, jdbc:mysql://127.0.0.1:3306/test2).</p>
  
  <p>Now we are going with different database which is DB2. so i was unable to find any samples for this scenario using abstract routing datasource. </p>
  
  <p>Can anyone give any directions ?  </p>
  
  <p>This is my code block:  </p>
  
  <p>i have defined 3 datasources itemDataSource, custDataSource, orderDb2DataSource in dao.xml .</p>
  
  <p>how to configure the second session factory to the the transaction manager ?</p>
  
  <pre><code>&lt;bean id="dataSource" class="com.test.DatabaseRoutingDataSource"&gt;
          &lt;property name="targetDataSources"&gt;
              &lt;map key-type="com.test.dao.DatabaseType"&gt;
                  &lt;entry key="ITEM" value-ref="itemDataSource"/&gt;
                  &lt;entry key="CUSTOMER" value-ref="custDataSource"/&gt;
                  &lt;entry key="ORDER_DB2" value-ref="orderDb2DataSource"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
          &lt;property name="defaultTargetDataSource" ref="itemDataSource" /&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource"&gt;
              &lt;ref bean="dataSource" /&gt;
          &lt;/property&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;/WEB-INF/hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySqlDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;!-- Added for DB2 Database --&gt;
      &lt;bean id="sessionFactoryDB2" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource"&gt;
              &lt;ref bean="dataSource" /&gt;
          &lt;/property&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;/WEB-INF/hibernate.db2.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.DB2Dialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;!-- Added for DB2 Database --&gt;
  
      &lt;bean id="transactionManager1"
           class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
              &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  </code></pre>