I have a table that is linked to an another table with a foreign key field and the field itself is nullable. That means a row in a first table may or may not have a corresponding row in another.
For the sake of simplicity let’s name the first table Foo and the second Bar.
Now when I query rows from Foo and try to order them by a field from Bar like this:
FROM Foo ORDER BY Bar.name
The result shows only these values from Foo where the field bar_id is not null. What is the best possible way to also include these rows from Foo, which don’t have a corresponding row in Bar.
Currently I have a big and sloppy method which takes values from filterMap and sortMap and appends them to a StringBuffer resulting a HQL query.
I have heard something about Criteria API but don’t know if it can help me past this situation.
You just need to do a left join rather than an inner join: