HQL语句,批量删除多行记录

a264424163 2011-03-18 10:07:42
mySql里这样写的。

delete from test1 where id in (1,2,3)

如何在Hibernate中用hql语句实现?

String hql="DELETE test1 WHERE id in (?)";

传个字符串进去,例如("1,2,3")

但只能删除id为1的记录,不能实现三条记录全部删除!

知道的指导下、谢谢、
...全文
1313 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
me_xyz 2011-11-20
  • 打赏
  • 举报
回复
学习了 今天刚好用到
完美灬缺陷 2011-03-18
  • 打赏
  • 举报
回复
String str = "1,2,3"

String hql="DELETE test1 WHERE id in ("+str+")";

执行hql
悲伤的驴 2011-03-18
  • 打赏
  • 举报
回复
String str = "1,2,3"

String hql="DELETE test1 WHERE id in ("+str+")";

执行hql
学习Java中 2011-03-18
  • 打赏
  • 举报
回复
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;
zn85600301 2011-03-18
  • 打赏
  • 举报
回复
HQL 操作的是对象

你可以把 id为 1,2,3的对象封装到一个集合里 hibernate有直接封装的删除集合的方法

或者你直接执行SQL
Nodin 2011-03-18
  • 打赏
  • 举报
回复
http://blog.csdn.net/hbcui1984/archive/2006/12/05/1431011.aspx
yukiMark 2011-03-18
  • 打赏
  • 举报
回复
感觉还是直接用Statem执行SQL比较好
lxu2222 2011-03-18
  • 打赏
  • 举报
回复
in 语句是不能使用 ? 的

67,512

社区成员

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

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