鉴于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。
转载于:https://my.oschina.net/u/2405670/blog/701312