hibernate in 查询

类别:Java 点击:0 评论:0 推荐:

   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(绝对是不可能的).

本文地址:http://com.8s8s.com/it/it10694.htm