集合对象上的 JPQL maxResults

发布于 2024-09-28 16:54:05 字数 410 浏览 1 评论 0原文

我有以下情况:类 Event 具有 Participant 对象的集合,但类 Participant 没有任何对事件的引用。因此,我需要获取给定活动的前 5 位最近参与者,只是不知道如何做到这一点。我知道在完成查询后,我只需要通过在实体管理器中设置 maxResults 来限制结果。这样做的原因是,当我只需要显示 5 个参与者时,让所有参与者始终参与会影响应用程序性能。

使用 JPQL 我可以轻松检索具有给定参与者的事件: select e from Event e where :participant in elements(e.participants) order by e.creationDate desc

但是我如何选择给定事件的参与者,我的意思是在某种程度上让我有可能限制 maxResults 的数量,例如上面的查询?

非常感谢 蒂亚戈

I have the following situation: a class Event that has a collection of Participant objects, but the class Participant don't have any reference to event. So, I need to get the first 5 most recent participants of a given event, just could not figure out how to this. I know that after get the query done I just need to limit the results by setting the maxResults in my entityManager. The reason to do this is because by getting all the participants all the time when I need to show just 5 is impacting application performance.

Using JPQL I can easily retrieve the events that have a given participant:
select e from Event e where :participant in elements(e.participants) order by e.creationDate desc

But how could I select the participants of a given event, I mean in a way that give me the possibility to limit the number maxResults like in the query above?

Many thanks
Thiago

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

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

发布评论

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

评论(1

没有伤那来痛 2024-10-05 16:54:05

你尝试过吗

SELECT p FROM Event e JOIN e.participants p 
WHERE e.id = :id ORDER BY p.participationTime DESC

Have you tried

SELECT p FROM Event e JOIN e.participants p 
WHERE e.id = :id ORDER BY p.participationTime DESC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文