Hibernate Criteria Order By

后端 未结 3 644
执笔经年
执笔经年 2021-01-04 02:58

I have a table called Gift, which has a one-to-many relationship to a table called ClickThrough - which indicates how many times that particular Gift has been clicked. I nee

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 03:16

    You have a one-to-many relationship from Gift to ClickThrough so I assume each ClickThrough is a record with some datetime or other information associated with it. In this case, I would add a "count" field to your mapping file and attach the ordering to the criterion:

    criterion.add(Order.asc(count)))

    The mapping property looks something like:

    If you can't or don't want to change the mapping file, you could use Collections.sort() with a Comparator though it seems less efficient having to return so much data from the DB.

提交回复
热议问题