1.HQL不同于SQL,from必须是项目中table反转后对应的class的名字。

2.如何使用参数生成HQL语句:

String hql = "from User where userId=? ";
Query query = session.createQuery(hql);
query.setParameter(0, userId);  //替代第0个问号

3.HQL不能写limit ,不过他有自带的方法可以设置,效果一样

query.setMaxResults(maxCount);  //设置获取的数量
query.setFirstResult(firstResult);    //设置从第几个开始获取
return query.list();                      //返回获取的结果

 

相关文章:

  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2021-11-08
  • 2021-11-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-04-16
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
相关资源
相似解决方案