Hibernate查询满足条件记录总数,请在下面代码后面添加代码:SessionFactory sf = new Configuration().configure().buildSessionFactory();    
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
String hql="select count(*) from jobTime where model>=?";  
Query query = session.createQuery(hql);
query.setString(0, content);...怎样将查询的这个int数赋值给一个变量?

解决方案 »

  1.   

    int recordCount = (Integer)session.createQuery(hql).list().get(0);
    这样就可以了
      

  2.   

                 int count=0;
    String hql="select count(*) from jobTime where model>=?";  
    Query q=super.getSession().createQuery(hql);
    q.setInteger(0, goodsId);
    List all=null;
    all=q.list();
    if(all.size()>0)
    {
    count=(Integer)all.get(0);
    }
    return count;