mySql里这样写的。delete from test1 where id in (1,2,3)如何在Hibernate中用hql语句实现?String hql="DELETE test1 WHERE id in (?)";传个字符串进去,例如("1,2,3")但只能删除id为1的记录,不能实现三条记录全部删除!  知道的指导下、谢谢、

解决方案 »

  1.   

    HQL 操作的是对象你可以把 id为 1,2,3的对象封装到一个集合里 hibernate有直接封装的删除集合的方法或者你直接执行SQL
      

  2.   

     String  ids[]=new  String[]{"1","2","3"};    
        
     String  hql=  "  from Appinfo where id  in  (?)";    
        
      Query  query  =  session.createQuery(hql);    
     query  .setParameterList(ids);    
       
     see:  
       
      Query  setParameters(Object[]  objectArray,  Type[]  typeArray)  throws  HibernateException;    
        Query  setParameterList(String  string,  Collection  collection,  Type  type)  throws  HibernateException;    
        Query  setParameterList(String  string,  Collection  collection)  throws  HibernateException;    
        Query  setParameterList(String  string,  Object[]  objectArray,  Type  type)  throws  HibernateException;    
        Query  setParameterList(String  string,  Object[]  objectArray)  throws  HibernateException; 
      

  3.   

    String str = "1,2,3"String hql="DELETE test1 WHERE id in ("+str+")";执行hql
      

  4.   

    感觉还是直接用Statem执行SQL比较好
      

  5.   

    http://blog.csdn.net/hbcui1984/archive/2006/12/05/1431011.aspx
      

  6.   

    String str = "1,2,3"String hql="DELETE test1 WHERE id in ("+str+")";执行hql