Say, i have an entity 开发者_StackOverflowthat has a history of operations as a collection. I want to sort entities by the date of the latest operation (it's the first element of history).
i'd like to do something like this:
criteria.addOrder(Order("history[0].date"))
is this possible?
As far as I know, Criteria only supports ordering by mapped properties, so perhaps mapping the date of last modification as computed property (using the formula attribute of the property tag) will do the trick.
Granted, this is ugly, but since nobody has posted a better approach so far ...
Edit: The query also might not perform too well, perhaps adding this as a redundant column to your entity table is a better option.
Not at all likely.
The data for your history is in another table, and to order by this relation you're going to need more complex criteria at least involving some sort of join to the other table, and I suspect perhaps an alias.
Post the mapping of your class, and we might be able to give a hint of how to do this.
精彩评论