spring的hibernateTemplate中hql如何使用in??
Object[] piid = processInstanceIds.toArray();
return hibernateTemplate.find("select d from Document d where d.processInstanceId in (?)",piid)我这样用报错提示:Remember that ordinal parameters are 1-based!查了下说明是:hql语句里不需要参数,应该是把 in(?) 中的?当字符串解释了.

解决方案 »

  1.   

    return hibernateTemplate.find("select d from Document d where d.processInstanceId in (?)",piid);
    (?)是什么数据?
      

  2.   

    这里最好不要用占位符,直接拼接字符串吧,多个值用逗号隔开,比如:
    String ids = "1,2,3";
    String hql = "select d from Document d where d.processInstanceId in (" + ids + ")";
      

  3.   

    如果还有子查询,就这样:// 根据公司ID和指定年月获得业务员完成的业绩
    public BigDecimal getConstFeeAll(Integer year, Integer month, String deptId) {
    String hql = "select sum(finalMoney) from DecoConstruction where year(createDate)=? and month(createDate)=? and decoDecoration.id in (select decoDecoration.id from DecoDistribute where coreEmployee.department.id in (" + deptId + ") and type=? and isAvalibled=?)";
    Object object = getObject(hql, new Object[]{ year, month, DecoDistribute.TYPE_SALESMAN, true });
    return (null != object ? (BigDecimal) object : new BigDecimal(0d));
    }
      

  4.   

    用这个吧return getHibernateTemplate().execute(new HibernateCallback<List<Brand>>() {
      @SuppressWarnings("unchecked")
      @Override
      public List<Brand> doInHibernate(Session session)
      throws HibernateException, SQLException {
    return session.createQuery("select distinct o.brand from ProductInfo o where o.productType.id in(:typeids)")
         .setParameterList("typeids", typeids)//typeids为集合对象,如果是数组可以自己转下Arrays.asList();
         .list();
    }
    });
      

  5.   

    2楼说的那样,不用使用占位符,直接拼接sql就可以
      

  6.   

    hibernateTemplate.find()只能查询单个语句返回值是序列化接口即select所取得的值得主键,要搜索多个数据方法 如 4楼 所示
      

  7.   

    hibernateTemplate.save()只能插入单个语句返回值是序列化接口即select所取得的值得主键,要保存多个数据方法 如 4楼 所示
      

  8.   

    用getHibernateTemplate().find("from Document d where d.processInstanceId in (?)",new Object[]{processInstanceIds.toArray});试试