1. 原生sql

String hql="select count(*) from product" ;//此处的product是数据库中的表名 
Query query=session.createSQLQuery(hql); 
List<BigInteger> list=query.list(); //此处胡一定要注意是Bignter类型的,傻了吧唧的试了好多(Long,Integer)都报错 
count = list.get(0).intValue();

 

2.hql语句

 String hql="select count(*) from Product";//此处的Product是对象
 Query query = session.createQuery(hql);
 count=((Long) query.setCacheable(true).uniqueResult()).intValue();//此处用Long类型进行转换

 

 

 

相关文章:

  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-11-20
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2021-12-27
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2022-03-08
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案