How to sort by number of votes in another table?
In hibernate I have a table/class Question and a table/class Vote. Vote.questionId is a foreign key for Question.id.
I want to sort the question by the number of votes.
I am executing
session.createQuery("from Question q, Vote v where q.id = v.questionId group by q.id orde开发者_开发知识库r by count(v) desc")
But I get "could not execute query"
If you're using groups you'll need to select fields specifically just like in SQL, so your query will look like:
select q.id, q.title, count(v) from Question q, Vote v where q.id = v.questionId
group by q.id, q.title
order by count(v) desc
cheers!
精彩评论