项目中需要连接两个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的管理。不知道行不行?
麻烦了!
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的管理。不知道行不行?
麻烦了!
解决方案 »
- struts1错误求解!
- 关于一个简单的spring 1.X前置通知
- 最近要弄个CRM系统,想找一个开源的作二次开发 openCRX
- Hibernate jpa 注解需要导入那几个包
- tomcat版本问题
- webservice时出现"invalid active port"错误
- excel导出中文,早linux部署下得到的为乱码,在window下没问题,求解决??
- 有没有在jbuilder8中使用jboss,以及开发ejb和jsp的详细资料?
- SUN ONE application server是什么东西??
- 关于J2EE的问题,急急急???
- 求助:关于POI中的插入数据问题?谢谢!在线等.......
- java与消息队列的通讯
SessionFactory sessionFactory = (SessionFactory)application.getBean("sessionFactory");
//application->Spring容器
Session sessionB = sessionFactoryb.getCurrentSession();
Session session = sessionFactory.getCurrentSession();