<span style="font-size:18px;">Session session = sessionFactory.getCurrentSession();
List list = session.createQuery(hql语句).list();
//<span style="background-color: rgb(102, 255, 153);">返回的是当前操作实体的list集合</span>
Long count = (Long)session.createQuery("SELECT COUNT(*) FROM "+clazz.getSimpleName()).uniqueResult();
//<span style="background-color: rgb(255, 102, 102);">注意这里返回要转为Long类型的</span>
//用的时候可通过count.intValue()得到int类型
List list = session.createSQLQuery(sql语句).list();
//<span style="background-color: rgb(102, 255, 153);">返回的是普通list集合,和操作的实体没有关系</span>
List list = session.createSQLQuery(sql语句).<span style="background-color: rgb(102, 255, 153);">addEntity(xxxx.class)</span>.list();
//返回的是<span style="background-color: rgb(102, 255, 153);">将数据封装到xxxx实体</span>中的list集合
BigInteger count = (BigInteger) session().createSQLQuery("select count(*) from "+clazz.getSimpleName().toLowerCase()).uniqueResult();
//<span style="background-color: rgb(255, 102, 102);">注意这里返回要转为BigInteger 类型的</span>
//用到的时候可通过count.intValue()得到int类型</span>
hibernate中query和sqlquery的区别
最新推荐文章于 2020-08-30 20:18:56 发布