cndavy

导航

 

addScalar 对带小数点的字段名好像不支持

strQuery=queryString.substring("select".length(),iPos);
                StringBuffer  fieldStr=new StringBuffer();
                for(String s :strQuery.split(",")){
                    String  s_s=s.trim().replace(".","_");
                    fieldStr.append(" ").append(s).append(" as ").append(s_s).append(" ,");
                 }
                fieldStr.delete(fieldStr.length()-1,fieldStr.length());

session.createSQLQuery("select ns.uuid as ns_uuid from Md_Namespace ns       ").addScalar("ns_uuid", Hibernate.STRING).list() 

带参数查询count 

strQuery = "select count(*) " + queryString.substring(iPos);

                    SQLQuery    queryCount = session.createSQLQuery( strQuery);                     if (parameters != null) {                         for (int i = 0; i < parameters.length; i++) {                             queryCount.setParameter(i, parameters[i]);                         }                     }                     queryCount.addScalar("count(*)",Hibernate.INTEGER);                     totalCount=(Integer)queryCount.uniqueResult();

 

 

 

posted on 2013-03-01 10:42  cndavy  阅读(406)  评论(0编辑  收藏  举报