StringBuffer buf = new StringBuffer();
if (!forObject) {
buf.append("select count(*) ");
}
buf.append("from Agent agent where 1=1 ");
String gradeId = (String)conditions.get("gradeId");
if(gradeId != null && !gradeId.equals("") && gradeId != ""){
buf.append(" and agent.gradeId=").append(gradeId);
}
buf.append(" and agent.agentId in (:agentIds) ");
Query query = sess.createQuery(buf.toString());
List ids = CommisionInfoDelegateExt.findAgentIdList(conditions);
System.out.println("ids.length=" + ids.size());
query.setParameterList("agentIds",
ids);
当ids长度为0(空记录)时,query.list()出错.没办法,现在在ids.add("-1"),塞入一条绝对不存在的记录id(绝对是不可能的).
博客主要围绕Hibernate查询展开,使用StringBuffer构建查询语句,根据条件拼接SQL。当查询所需的ids列表长度为0时,query.list()会出错,为解决此问题,采用在ids中添加绝对不存在的记录id的方法。
1087





