事实上你的 channelID 是 int 类型的。
当你 把一个字符串 "1,2,3" 传入的时候.
你的hql 会被解析为:delete from changels where id in ('1,2,3')
我也不晓得这样为什么会把 id 为1 的删除.但是 hibernate 在批处理的时候是没有jdbc好的.
所以象这种逻辑一般直接用 createSQLQuery 处理比较好。

解决方案 »

  1.   

    squallffx (squall) 在CSDN社区共有可用分:870, 已花费可用分:45, 剩余可用分:825你有825分,竟然哭穷!
    算了,建议你
    1 逐个删除还了,而且hibernate支持批量删除,Batch 的!性能也很好!
    2 使用NativeQuery 吧!
      

  2.   

    hibernate本身API去做批量删除更新都是不推荐的 或者用调存储过程的办法也是可行的tx = session.beginTransaction();
    Connection con=session.connection();String procedure = "{call batchUpdateCustomer(?) }";
    CallableStatement cstmt = con.prepareCall(procedure);
    cstmt.setInt(1,0); 
    cstmt.executeUpdate();
    tx.commit();
      

  3.   

    public void deleteChannel(Object... channelID){
    if(channelID==null)return;
    StringBuilder str=new StringBuilder("delete from Channels wher id in (?");
    for(int i=1;i<channelID.length;i++){
    str.append(",?");
    }
    str.append(")");
    Query q = this.session.createQuery(hql); 
    for(int i=0;i<channelID.length;i++){
    q.setString(i+1,channelID[i].toString());
    }
    q.executeUpdate();
    this.session.beginTransaction().commit();