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
Why this hibernate template bulkUpdate doesn't work
提问by user6778654
Oracle 10g, Hibernate 3.4
甲骨文 10g,休眠 3.4
This update (based on long user.userId
value) 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.language
value) 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
休眠文档说:
- 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");