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
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.