spring的hibernateTemplate中hql如何使用in

mozhx2002 2012-10-23 05:20:03
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(?) 中的?当字符串解释了.
...全文
1110 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
saisi 2013-02-28
  • 打赏
  • 举报
回复
用getHibernateTemplate().find("from Document d where d.processInstanceId in (?)",new Object[]{processInstanceIds.toArray});试试
ShineQiu 2012-10-25
  • 打赏
  • 举报
回复
hibernateTemplate.save()只能插入单个语句返回值是序列化接口即select所取得的值得主键,要保存多个数据方法 如 4楼 所示。。。
ShineQiu 2012-10-25
  • 打赏
  • 举报
回复
看错了,看成多值查询了,用2楼方法
ShineQiu 2012-10-25
  • 打赏
  • 举报
回复
hibernateTemplate.find()只能查询单个语句返回值是序列化接口即select所取得的值得主键,要搜索多个数据方法 如 4楼 所示。。。
lzh_me 2012-10-25
  • 打赏
  • 举报
回复
2楼说的那样,不用使用占位符,直接拼接sql就可以
吉他猪 2012-10-24
  • 打赏
  • 举报
回复
用这个吧

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();
}
});

s478853630 2012-10-24
  • 打赏
  • 举报
回复
如果还有子查询,就这样:

// 根据公司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));
}
s478853630 2012-10-24
  • 打赏
  • 举报
回复
这里最好不要用占位符,直接拼接字符串吧,多个值用逗号隔开,比如:
String ids = "1,2,3";
String hql = "select d from Document d where d.processInstanceId in (" + ids + ")";
  • 打赏
  • 举报
回复
return hibernateTemplate.find("select d from Document d where d.processInstanceId in (?)",piid);
(?)是什么数据?
小菜的粉丝 2012-10-24
  • 打赏
  • 举报
回复
in 后使用list

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧