title: Hibernate configuring multiple datasources and multiple session factories
body: <p>I am using Spring and Hibernate the spring configuration is as below. How do i configure two data sources, session factories. The transaction is managed using annotations. Please advise</p>
  
  <pre><code>&lt;!-- we can use annotations --&gt;
  &lt;context:annotation-config/&gt;
  
  &lt;!-- package to look for annotated classes --&gt;
  &lt;context:component-scan base-package="com.XXX.XXX.service.impl"/&gt;
  
  &lt;!-- we will manage transactions with annotations --&gt;
  &lt;tx:annotation-driven/&gt;
  
  
  &lt;bean id="transactionManager"   class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- configure hibernate session factory --&gt;
  
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close" p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
      p:url="jdbc:sqlserver://DB_NAME\DB_INSTANCE:DB_PORT;databaseName=DB_NAME;username=DB_USER;password=DB_PASSWORD;" /&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
     &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath: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.SQLServerDialect&lt;/prop&gt;
              &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt;
              &lt;prop key="show_sql"&gt;false&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  
  &lt;/bean&gt;
  </code></pre>