In one table I have:
oid | code_name |
---|---|
1 | 1 |
2 | NULL |
3 | 2 |
4 | 3 |
code name is foreign key on second table:
oid | name |
---|---|
1 | BANANA |
2 | APPLE |
3 | ORANGE |
My HQL is:
FROM table1 o ORDER BY o.code_name.name
but for some reason the result I got when I do the sort is sorted table without the null row.
oid | code_name | name |
---|---|---|
3 | 2 | APPLE |
1 | 1 | BANANA |
4 | 3 | ORANGE |
CodePudding user response:
When you put ORDER BY o.code_name.name
it means that you have to join the other table. Seem like Hibernate transform this HQL
to INNER JOIN
in plain SQL
.
You have to put LEFT JOIN
manually.
SELECT t1 FROM table1 t1
LEFT JOIN t1.code_name t2
ORDER BY t2.name