I have two databases wtis the same scheme.
My hibernate 3.2/Spring 3 application have one datasource (via jndi) for one each database, and one transactino manager (HibernateTransactionManager) for each datasource.
Question: Can i use one instance of session factory, that should use datasource associated with current transaction?
Suppose, there are the following methods.
@Transactional(readOnly = true, value = "tmDBOne")
public String db1() throws IOException {
dao.execute(); // dao uses injected session factory
}
@Transactional(readOnly = true, value = "tmDBTwo")
public void db2() throws IOException {
dao.execute(); // dao uses injected session factory
}
trnsaction managers:
<bean id="tmDBOne"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="dsDBOne/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="tmDBTwo"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="dsDBTwo/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>