Hi,
I am using the new spring-mybatis integration module to access an
Oracle database through Mybatis. And I need to switch the database
based on user input (and without restarting the app server). To
achieve this, I used Spring's AbstractRoutingDataSource on similar
lines as mentioned in this blog -
http://blog.springsource.com/2007/01/23/dynamic-datasource-routing
and it seems that the switch is happening as expected but I am getting
errors (more often than not) like 'insufficient privilege to access
object <Schema>.<DBPackage>'. Its as if the new databse is being
accessed but the credentials used are from
the older datasource.
Any help in identifying why this might occur and the way to solve it
will be highly appreciated. Thanks!
This is my Spring configuration:
<bean id="dataSource"
class="com.x.y.datasource.MyRoutingDataSource">
<property name="targetDataSources">
<map key-type="com.x.y.datasource.AppDbMode">
<entry key="NORMAL" value="jdbc/PrimaryDB"/>
<entry key="MAINTENANCE" value="jdbc/SecondaryDB"/>
</map>
</property>
<property name="defaultTargetDataSource" value="jdbc/PrimaryDB"/>
</bean>
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:com/x/y/ibatis/
data/*.xml" />
</bean>
<bean id="siteSetupMapper"
class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface"
value="com.x.y.ibatis.data.SiteSetupMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>