Oracle 10g,hibernate3.4
此更新(基于long user.userId值)正确完成:
long user.userId
getHibernateTemplate().bulkUpdate("update Address address set address.preferred = 1 where address.user.userId = ?", 1l);
这个(基于String user.language值)抛出异常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");
有人知道为什么吗?
Hibernate文档说:
批量HQL查询中不能指定隐式或显式连接。子查询可以在where子句中使用,其中子查询本身可能包含联接。
因此,您需要用等效的子查询替换隐式连接:
getHibernateTemplate().bulkUpdate( "update Address address set address.preferred = 1 " + "where address.user in (select u from User u where u.language = ?)", "en");