HQL语句,批量删除多行记录 mySql里这样写的。delete from test1 where id in (1,2,3)如何在Hibernate中用hql语句实现?String hql="DELETE test1 WHERE id in (?)";传个字符串进去,例如("1,2,3")但只能删除id为1的记录,不能实现三条记录全部删除! 知道的指导下、谢谢、 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HQL 操作的是对象你可以把 id为 1,2,3的对象封装到一个集合里 hibernate有直接封装的删除集合的方法或者你直接执行SQL 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; String str = "1,2,3"String hql="DELETE test1 WHERE id in ("+str+")";执行hql 感觉还是直接用Statem执行SQL比较好 http://blog.csdn.net/hbcui1984/archive/2006/12/05/1431011.aspx String str = "1,2,3"String hql="DELETE test1 WHERE id in ("+str+")";执行hql Hibernate的动态关联 问个tomcat7集群的问题 struts标签Logic循环标签报错 专用于开发J2EE的集成Eclipse HQL查询的问题 struts1.1中validate返回错误后中文显示问题 *********各位仁兄,struts初学者的初学问题,100分招聘(高手们问题过于简单,不要见笑)******************* J2ee与J2SE的JDK有什么区别? 启动j2ee的错误 WebLogic数据源 关于hibernate使用oracle数据库sequence自增序列的问题 struts2配置没有错,对应属性也没有写错,但是没法上传文件
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;