项目中需要连接两个Oracle数据库,所以我写了两个hibernate配置文件,一个是“hibernate.cfg_b.xml”,另一个是“hibernate.cfg.xml”。
spring的配置文件(applicationContext.xml)中是以下配置:
<bean id="sessionFactoryb" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation" value="classpath:hibernate.cfg_b.xml"></property>
</bean>
 
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>现在想分别获得两个数据库连接的Session,该怎么获取,
PS: super.getHibernateTemplate().getSessionFactory().openSession();只可以获得一个。
Configuration con=new Configuration().configure("hibernate.cfg_b.xml");
Session sf=con.buildSessionFactory().openSession();
这种方法可以获得两个,但是脱离了Spring的管理。不知道行不行?
麻烦了!