After googling a little more, I found out MySQL needs an alias for count() in the order by clause to work :
SELECT HOSTS.*, count( SESSIONS.id ) as counted FROM HOSTS LEFT JOIN SESSIONS ON ( HOSTS.id = SESSIONS.referingHost ) GROUP BY HOSTS.id ORDER BY counted;
Which brings us to:
Query qReferers = sess.createSQLQuery("select {refHost}.*, count(sess.id) as counted from HOSTS as {refHost} left join SESSIONS sess on ({refHost}.id = sess.referingHost ) group by {refHost}.id order by counted LIMIT 30 ", aliases,classes );
Can this be mad eto work directly in the MySQL dialect? Using createSQLQuery solves the issue but shoots down portability etc...
|