集合对象上的 JPQL maxResults
我有以下情况:类 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过吗
Have you tried