private int getTotal(final int page, final int pageSize,final int productTypeId, final int progress,final String orderCode,final Date startDate, final Date stopDate,final String clientUserName) {
Session session = (Session) this.hibernateTemplate.getSessionFactory().openSession(); StringBuffer buff = new StringBuffer();
buff.append(" from Orders o ");
boolean where = false;
if(productTypeId !=0 && !"".equals(productTypeId)){
buff.append(" where o.workBillInfo.productType.productTypeId=:productTypeId ");
where = true;
}
if (progress!=0 && !"".equals(progress)) {
if(where){
buff.append(" and ");
}else{
buff.append(" where ");
where = true;
}
buff.append("  o.progress.progressCode=:progress ");
}  
if (progress==0) {
if(where){
buff.append(" and ");
}else{
buff.append(" where ");
where = true;
}
buff.append("  o.progress.progressCode!=:progressC ");
}

if (orderCode != null && !"".equals(orderCode)) {
if(where){
buff.append(" and ");
}else{
buff.append(" where ");
where =true;
}
buff.append(" o.orderCode=:orderCode ");
}

if (startDate != null && !"".equals(startDate)
&& stopDate!= null && !"".equals(stopDate)) {
if (where) {
buff.append(" and ");
} else {
buff.append(" where ");
where = true;
}
buff.append(" o.orderTime between :startDate and :stopDate ");
}
if(where){
buff.append(" and ");
}else{
buff.append(" where ");
where =true;
}
    buff.append(" o.clientLoginInfo.clientUserName=:clientUserName ");
    Query query=session.createQuery(buff.toString());   
 
  if (progress!=0 && !"".equals(progress)) {
query.setInteger("progress", progress);

  if (productTypeId != 0 && !"".equals(productTypeId)) {
query.setInteger("productTypeId", productTypeId);
}
  if (orderCode != null && !"".equals(orderCode)) {
query.setString("orderCode", orderCode);
}
  if (progress==0) {
query.setInteger("progressC", 17);

if (startDate != null && stopDate != null) {
query.setDate("startDate", startDate);
query.setDate("stopDate", stopDate);
}
query.setString("clientUserName", clientUserName);
return query.list().size();
}执行了一次  控制台打印出20多次同样的sql