Hibernate HQL 查询:如何在 where 子句中正确使用 ANY 函数?
我正在努力理解 HQL 查询中的错误:
public List<Pats> getIds(List<String> patIds) {
Session session = getSession();
String hql = "from OurPats where patId = any (:patIds)";
// String hql = "from OurPats where patId in (:patIds)";
return session.createQuery(hql).setParameterList("patIds", patIds).list();
}
...注释掉的行工作正常,但我希望非工作 ANY 比较的功能,因为 patIds.size() 可以大于 2^15 (导致postgresql 中断)。
从 http://docs.jboss.org/ 来看hibernate/core/3.3/reference/en/html/queryhql.html ANY 函数应该可以工作。在其他论坛问题中,人们说不要使用上面链接中规定的 elements 函数(我尝试过 elements 并收到 IDENT 错误)。上面的代码产生一个 org.hibernate.hql.ast.QuerySyntaxException: 意外的 token: : 错误。
有什么想法吗?感谢您的帮助。
I'm struggling to understand my error in an HQL query:
public List<Pats> getIds(List<String> patIds) {
Session session = getSession();
String hql = "from OurPats where patId = any (:patIds)";
// String hql = "from OurPats where patId in (:patIds)";
return session.createQuery(hql).setParameterList("patIds", patIds).list();
}
...the commented out line works properly, but I want the functionality of the non-working ANY comparison as patIds.size() can be greater than 2^15 (causing postgresql to break).
Judging from http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html the ANY function should work. In other forum questions people say not to use the elements function as is stipulated in the above link (I've tried with elements and I get an IDENT error). The above code produces an org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : error.
Any ideas? Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,
= ANY
相当于IN
(我认为它们会被优化器转换为相同的查询)。来自 PostgreSQL 文档:所以我不认为使用
= ANY
无论如何都能解决你的问题。当然,我没有上下文,但您确定执行超过 2^15
OR
比较真的有意义吗?As far as I know,
= ANY
is equivalent toIN
(and I think they will be transformed into the same queries by the optimizer). From the PostgreSQL documentation:So I don't think using
= ANY
will solve your problem anyway.Of course, I don't have the context but are you sure that performing more than 2^15
OR
comparisons really makes sense?不确定您想要“任何”而不是“在”的功能是什么意思。我所知道的每个 DBMS 都将它们视为同义词。
= ANY 不允许用于 MySQL 中的列表,仅适用于子查询。表面上你已经将方言设置为 MySQL 并且 Hibernate 知道这一点?
http://dev.mysql.com/ doc/refman/5.5/en/any-in-some-subqueries.html
Not sure what you mean by wanting the functionality of 'any' rather than 'in.' Every DBMS I know treats them as synonymous.
= ANY is not allowed for lists in MySQL, only for subqueries. Ostensibly you have your dialect set to MySQL and Hibernate knows this?
http://dev.mysql.com/doc/refman/5.5/en/any-in-some-subqueries.html