spring 多数据源 sessionFactiory只加载了一个
请教大虾们,我按照网上前辈们经验配置了ssh多数据源,结果启动tomcat时sessionFactiory里的hibernate.hbm.xml文件只加载了一个sessionFactiory里的,另一个没加载。为什么啊。
上段代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="rdataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@10.103.2.10:1521:SW01</value></property>
<property name="username"><value>system</value></property>
<property name="password"><value>manager</value></property>
</bean>
<bean id="wdataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@10.103.2.102:1521:SW01</value></property>
<property name="username"><value>system</value></property>
<property name="password"><value>manager</value></property>
</bean>
<bean id="rsessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="rdataSource"/>
</property>
<property name="mappingResources">
<list>
<value>hibernate/Poordr.hbm.xml</value>
<value>hibernate/Povnms.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</prop>
</props>
</property>
</bean>
<bean id="wsessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="wdataSource"/>
</property>
<property name="mappingResources">
<list>
<value>hibernate/Bsprice.hbm.xml</value>
<value>hibernate/Order.hbm.xml</value>
<value>hibernate/Orderdetail.hbm.xml</value>
<value>hibernate/Orderreseive.hbm.xml</value>
<value>hibernate/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</prop>
</props>
</property>
</bean>
<bean id="rtransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="sessionFactory" ref="rsessionFactory"/>
<qualifier value="qread"/>
</bean>
<bean id="wtransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="sessionFactory" ref="wsessionFactory"/>
<qualifier value="qwrite"/>
</bean>
<!--1、read数据源 事务管理拦截器 -->
<tx:annotation-driven transaction-manager="rtransactionManager"></tx:annotation-driven>
<!--2、write数据源 事务管理拦截器-->
<tx:annotation-driven transaction-manager="wtransactionManager"></tx:annotation-driven>
</beans>
打印的日志
[2013-08-06 15:57:46][HbmBinder ]INFO Mapping class: com.pojo.BspricePojo -> TB_BSPRICE
[2013-08-06 15:57:46][HbmBinder ]INFO Mapping class: com.pojo.OrderPojo -> TB_ORDER
[2013-08-06 15:57:46][HbmBinder ]INFO Mapping class: com.pojo.OrderdetailPojo -> TB_ORDERDETAIL
[2013-08-06 15:57:46][HbmBinder ]INFO Mapping class: com.pojo.OdreseivePojo -> TB_ORDERRESEIVE
[2013-08-06 15:57:46][HbmBinder ]INFO Mapping class: com.pojo.UserPojo -> TB_USER
[2013-08-06 15:57:46][HbmBinder ]INFO Mapping collection: com.pojo.OrderPojo.children -> TB_ORDERDETAIL
.....
Caused by: org.hibernate.MappingException: An association from the table TB_BSPRICE refers to an unmapped class: com.pojo.PovnmsPojo
...
就是我wsessionFactory里的映射加载了,另一个rsessionFactory里的没加载,而我加载的hbm.xml中many-to-one了没加载的一个class,所以后面出现错误。
spring多数据源
[解决办法]
spring多数据源方案,可以到我的博客看看