开发者

How to retrieve last "m" instances from a "1-n" relationship using JPQL?

Is there anyway to retrieve the last "m" in开发者_运维知识库stances from a 1 to n relationship using JPQL?

Ex. Retrieve the last "m" actions for the following "x" Users.


For a single user you can just use maxResults on the Query.

Query query = em.createQuery("select u.actions from User u where u.id = :id");
query.setMaxResults(10);

Otherwise, how do you determine the "last" instances as there is no order in a OneToMany, or do you have an order column?

Perhaps something like,

Select a from User u join u.actions a where a.index >= (Select (Max(a2.index) - 10) from Action a2 where a2.user = u)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜