hibernate 执行此条delete Lc_Admin where id in(?)只能删除第一个ID

怀之若谷 2015-09-15 07:11:43
​public boolean runByHql(String hql, Object...params) {
try {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hql);
if(params != null && params.length>0){
for(int i=0;i<params.length;i++){
query.setString(i, params[i].toString());
}
}
query.executeUpdate();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

​String hql = "delete Lc_Admin where id in(?)";

为什么执行此条hql语句时,能执行成功。但是删除多个id时[1,2,3],只能执行成功一个id的数据[1]!!!
...全文
118 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
打出你的sql语句看下,是in (1) 还是 in (1,2,3)
oxcow 2015-09-15
  • 打赏
  • 举报
回复
给你个例子吧

 @Override
    public int updateExpirationData(String[] codes, Date date, String oper) {
        Session session = getSession();
        String hql = "update Coupon set expirationData = ?, status = ?, updateTime = ?, lastOper = ? where couponCode in (:codes)";
        Query query = session.createQuery(hql);
        query.setDate(0, date);
        query.setInteger(1, CouponStatus.UNUSED.ordinal());
        query.setDate(2, new Date());
        query.setString(3, oper);
        query.setParameterList("codes", codes);
        int affectRows = query.executeUpdate();
        releaseSession(session);
        return affectRows;
    }
gukuitian 2015-09-15
  • 打赏
  • 举报
回复
你的hql只有一个问号?
weixin_31313899 2015-09-15
  • 打赏
  • 举报
回复
sql执行语句只执行一遍,没有在循环里面

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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