Hibernate Select Top and Bottom n Rows with Criteria

前端 未结 7 1987
孤街浪徒
孤街浪徒 2021-02-07 00:33

Let\'s say I have two tables, Books and Reviews. Reviews has a column, stars, that can have a value between 1 and 5. A Book can have many Reviews.

How would I select al

相关标签:
7条回答
  • 2021-02-07 01:04

    You could always set the ordering asc/desc and then limit the results.

    ex:

    criteria.addOrder(Order.desc("id"));
    criteria.setMaxResults(1);
    

    Not sure where it stands with regard to efficiency. I'm assuming that it's doing the filtering after the fact that a Select * has been fired off?

    0 讨论(0)
提交回复
热议问题