开发者

JPA2 how to select n entities starting at the i'th entity/row

I have let the model开发者_JAVA技巧ing tools in my IDE create entities from tables, so each entity is one record. How can I select n records starting at the i'th record, such that I may easily implement pagination?

Using criteria queries but a simple reference should be enough. My tables are varied so I can't do this by key. I can do this with native queries but am uncertain how at the moment how a criteria query and native query can be combined.

Currently I am returning a list and discarding the portion I do not want, this is proving to be too inefficient.


you can use the combination of javax.persistence.Query#setFirtsResult and javax.persistence.Query#setMaxResult if you don't insist on using criteria.

Criteria criteria 
        = session.createCriteria(SomeClass.class);
criteria.setFirstResult(0);
criteria.setMaxResults(10);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜