日期:2014-05-16 浏览次数:20450 次
写两个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,
SessionFactory sessionFactoryb = (SessionFactory)application.getBean("sessionFactoryb"); SessionFactory sessionFactory = (SessionFactory)application.getBean("sessionFactory"); //application->Spring容器 Session sessionB = sessionFactoryb.getCurrentSession(); Session session = sessionFactory.getCurrentSession();?