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 need to query for all of the Gift objects, ordered by ClickThrough count. I do not need the ClickThrough count returned, as I don’t need anything done with it, I just want to use it for purposes of ordering.
I need the query to return a List of Gift objects directly, just ordered by ClickThrough count. How do I do this using the Criteria API? I can find a lot of documentation out there on similar information to this, but nothing quite like what I need.
If you want to return a list of entities or properties in combination with a count you will need a group by. In criteria this is done through
ProjectionListandProjections. e.g.However, since you’re using
ProjectionListyou will also need to use AliasToBeanConstructorResultTransformer.