oracle 为什么这个休眠模板批量更新不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5368522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:07:10  来源:igfitidea点击:

Why this hibernate template bulkUpdate doesn't work

javaoraclehibernatespring

提问by user6778654

Oracle 10g, Hibernate 3.4

甲骨文 10g,休眠 3.4

This update (based on long user.userIdvalue) is done correctly:

此更新(基于long user.userId值)已正确完成:

getHibernateTemplate().bulkUpdate("update Address address set address.preferred = 1 where address.user.userId = ?", 1l);

This one (based on String user.languagevalue) throws an exception ORA-00971: missing SET keyword:

这个(基于String user.language值)抛出异常ORA-00971: missing SET keyword

getHibernateTemplate().bulkUpdate("update Address address set address.preferred = 1 where address.user.language = ?", "en");

Anybody knows why?

有谁知道为什么?

回答by axtavt

Hibernate documentationsays:

休眠文档说:

  • No joins, either implicit or explicit, can be specified in a bulk HQL query. Sub-queries can be used in the where-clause, where the subqueries themselves may contain joins.
  • 不能在批量 HQL 查询中指定隐式或显式连接。子查询可以用在 where 子句中,子查询本身可能包含连接。

So, you need to replace implicit join with the equivalent subquery:

因此,您需要用等效的子查询替换隐式连接:

getHibernateTemplate().bulkUpdate(
   "update Address address set address.preferred = 1 " +
   "where address.user in (select u from User u where u.language = ?)",
   "en");