JDOQL子查询计数问题

发布于 2024-09-28 07:41:04 字数 962 浏览 5 评论 0原文

我在使用 JDOQL(使用 DataNucleus)进行子查询计数时遇到问题。以下查询

SELECT this.price
FROM com.mysema.query.jdo.test.domain.Product
WHERE (SELECT count(other)
FROM com.mysema.query.jdo.test.domain.Product other
WHERE other.price > this.price) > a1
PARAMETERS java.lang.Long a1

导致异常

javax.jdo.JDOUserException: Cannot perform operation ">" on SubqueryExpression "(SELECT COUNT("OTHER".PRODUCT_ID) FROM PRODUCT "OTHER" WHERE "OTHER".PRICE > THIS.PRICE)" and IntegerLiteral "?"
    at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:390)
    at org.datanucleus.jdo.JDOQuery.executeWithArray(JDOQuery.java:321)

以下查询都不起作用:

SELECT this.price
FROM com.mysema.query.jdo.test.domain.Product
WHERE !(SELECT other
FROM com.mysema.query.jdo.test.domain.Product other
WHERE other.price > this.price).isEmpty()

确保子查询结果不为空的正确方法是什么?

I am having trouble with subquery counts with JDOQL (using DataNucleus). The following query

SELECT this.price
FROM com.mysema.query.jdo.test.domain.Product
WHERE (SELECT count(other)
FROM com.mysema.query.jdo.test.domain.Product other
WHERE other.price > this.price) > a1
PARAMETERS java.lang.Long a1

causes the Exception

javax.jdo.JDOUserException: Cannot perform operation ">" on SubqueryExpression "(SELECT COUNT("OTHER".PRODUCT_ID) FROM PRODUCT "OTHER" WHERE "OTHER".PRICE > THIS.PRICE)" and IntegerLiteral "?"
    at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:390)
    at org.datanucleus.jdo.JDOQuery.executeWithArray(JDOQuery.java:321)

The following query works neither :

SELECT this.price
FROM com.mysema.query.jdo.test.domain.Product
WHERE !(SELECT other
FROM com.mysema.query.jdo.test.domain.Product other
WHERE other.price > this.price).isEmpty()

What is the proper way to make sure that a subquery result is not empty?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥︴琐丶欲为 2024-10-05 07:41:04

我通过从 DataNucleus 2.0.4 升级到 2.1.2 解决了问题。第一个查询有效。

I got the problems fixed by upgrading from DataNucleus 2.0.4 to 2.1.2. The first query works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文