根据两个字段进行统计

hibernate qbc 无法实现having查询。

 

根据两个字段进行统计

(sql)

select t.asset_name,t.specs,count(*) from t_assetinfo t where t.type_id=2 group by t.asset_name,t.specs

 

(qbc)

Session sess = getHibernateTemplate().getSessionFactory().openSession();
  Criteria c = sess.createCriteria(TAssetinfo.class);
  if (assetinfoDTO.getHouseId() != null && assetinfoDTO.getHouseId() > 0) {
   c.add(Expression
     .eq("TWarehouse.houseId", assetinfoDTO.getHouseId()));
  }
  if (assetinfoDTO.getAssetTypeId() != null
    && assetinfoDTO.getAssetTypeId() > 0) {

   c.add(Expression.eq("TAssetType.typeId", assetinfoDTO
     .getAssetTypeId()));
  }
  ProjectionList prolist = Projections.projectionList();
  prolist.add(Projections.property(ASSET_NAME));
  prolist.add(Projections.property(SPECS));
  prolist.add(Projections.rowCount());
  prolist.add(Projections.sum(NET_VALUE));

  prolist.add(Projections.groupProperty(ASSET_NAME));
  prolist.add(Projections.groupProperty(SPECS));
  c.addOrder(Order.asc("assetName"));
  c.setProjection(prolist);
  c.setFirstResult((page - 1) * size);
  c.setMaxResults(size);

  List list = c.list();
  sess.close();

  Integer rowSize = this.queryStorageByAssetNameRowCount(assetinfoDTO);

  PageInfo pageResult = new PageInfo();
  pageResult.setCurrentPage(page);
  pageResult.setPerPageSize(size);
  pageResult.setTotalRowSize(rowSize);
  pageResult.setResult(list);
  return pageResult;

 

你可能感兴趣的:(sql,Hibernate,list,session,null,Integer)