当前位置:Gxlcms > 数据库问题 > hibernateTemplate获取jdbc数据库连接

hibernateTemplate获取jdbc数据库连接

时间:2021-07-01 10:21:17 帮助过:13人阅读

	@Test
	public void test(){
		//获取刷新模式
		this.getHibernateTemplate().getSessionFactory().openSession().setCacheMode(cachemode);
		//获取查询条件
		this.getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(class1);
		//获取数据库connection连接
		this.getHibernateTemplate().getSessionFactory().getCurrentSession().connection();
		//获取数据库connection连接sessionFactory 强转为SessionFactoryImplementor获取数据库连接
		((SessionFactoryImplementor)(this.getHibernateTemplate().getSessionFactory())).getConnectionProvider().getConnection();
	}
	
	
	spring封装的hibernateTemplate对象 进行jdbc操作.此处获取的sessionFactory就是hibernate的sessionFactory对象。


hibernateTemplate获取jdbc数据库连接

标签:java

人气教程排行