In my project, I am using 2 databases (i.e DB1 and DB2) interchangeably. However, in my Tomcat datasource, I currently have one datasource setup
Tomcat server.xml
Code:
...
<Resource name="jdbc/DB" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/DB">
<parameter>
<name>url</name><value>jdbc:jtds:sqlserver://XXXXXX/DB1</value>
</parameter>
...
hibernate.cfg.xmlCode:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/DB</property>
...
My question is: How do you tell Spring or Hibernate to delegate to the appropriate datasource given that I create another datasource name in Tomcat or hibernate config files?For example, class A is a DAO that access both databases (DB1 and DB2) and has 2 methods,
getDataFromDB1() and
getDataFromDB2(). How do you tell Spring or Hibernate to dispath datasource DB1 for method
getDataFromDB1() and datasource DB2 for method
getDataFromDB2()?