JPA group by 和可为 Null 的字段

发布于 2025-01-02 10:48:12 字数 219 浏览 1 评论 0原文

我的 jpa 有问题。 我正在使用 Criteria 创建一个查询,该查询必须返回使用适当的联接从多个表中检索的对象列表。问题是查询涉及的某些值可能为空。如果我不添加 group by 子句,一切都会正常工作,但如果我添加 group by 或 sum 之类的聚合函数,则空值不会出现在输出列表中。 真正奇怪的是,如果我将 hibernate 生成的查询放入 Toad 中,它会给出正确的结果列表。

提前致谢

I have a problem with jpa.
I'm creating a query using Criteria that have to return me a list of object retreived from multiple tables using appropriate joins. The problem is that some of the values involved with the query can be null. Everything works fine if I don't add the group by clause but if I add the group by or an aggregate function like sum, then the null values arent presente in the output list.
The thing that is really strange is that if I put the query generated by hibernate into Toad it gives me the correct result list.

Thanks in advance

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

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

发布评论

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

评论(1

白馒头 2025-01-09 10:48:13

NULL 值在 JPA 中大多被忽略,甚至在 SQL 中也是如此,请参阅 http://www.sqlsnippets。 com/en/topic-12656.html

NULL values are mostly ignored in JPA, even in SQL, see http://www.sqlsnippets.com/en/topic-12656.html

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