With a couple of modifications, I was able to get mooritze's suggestion to work.
First, I use "coalesce" instead of "nvl". Coalesce is supported by most major DBs (Oracle, MySQL, SQLServer) so it is more portable. nvl does not exist on MySQL, the database I am using.
Second, I added a "select b" clause to my HQL at the front. Otherwise, with the join on Category, I get back a list of object arrays, with a Button and a Category. I just want a list of Buttons.
So the final statement looks like
"select b from Button b left join Category cat order by coalesce(cat.order, 10000), b.order"
The only thing I'm not happy with is the hard-coded 10000 in the coalesce expression. I want the buttons without a category to be last, and as long as no category has a display order greater than 10000, this will work. But it's not very clean.
|