mysql使用hibernate,对查询到的表进行操作的时候报错,该怎么处理

一大波程序猿 2015-10-12 04:12:49
String hql = "delete from Comment bean where bean.parent.id in (select c.id from Comment c where c.user.id=?)";

报的错误是You can't specify target table 'Comment ' for update in FROM clause
上网查了发现mysql不支持在查询的结果集中在对这个表进行操作,我照着网上改了下改成
delete from Comment bean where bean.parent.id in (select temp.id from (select c.id from Comment c) temp where temp.user.id=?))

但是依旧报错,在mysql中却能执行,可能是hql语句跟sql语句并不能一样写,求大神帮忙
...全文
120 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
一大波程序猿 2015-10-14
  • 打赏
  • 举报
回复
那么我的问题就是想使用hql,却对hql语句不是很熟悉,不知道这种复杂的能不能写成一条
qq_20062767 2015-10-12
  • 打赏
  • 举报
回复
你写的这个是通用的sql语句,而不是hibernate的hql语句,所以你要使用Hibernate的另外一个方法来执行,session.createSQLQuery(),而不是session.createQuery()这个方法,如果你想使用hql语句的话,就要修改了,希望对你有用。

81,122

社区成员

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

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