EntityManager获取connection进行jdbc操做

鉴于hibernate一些查询的局限性,此次就碰到一不支持as别名、二来因须要连表查询select t1.id和t5.id,log上打印的sql语句在navicat中执行数据都是对的两个不一样的id,但在查询出来的Object[]数组中获取的两个字段值是同样的。这就尴尬了。
根据使用的jar版本不一样获取的方式会有差别,用em的unwrap()方法会报nusuchmethod异常。
EntityManager em = this.getJpaTemplate().getEntityManagerFactory()
			.createEntityManager();
Session session = (org.hibernate.Session) em.getDelegate();
SessionFactoryImplementor sf=(SessionFactoryImplementor)session.getSessionFacory(); 
Connection connection =sf.getConnectionProvider().getConnection();
*以后使用的方式就是最基础的jdbc操做了,记得在try-catch代码块中写,最后在finally中关闭connection、preparedstatement、resultset。
相关文章
相关标签/搜索