Recently I’ve encountered a tricky and hard to spot problem with JPA2, joins with null values and ordering. But finally I managed to solve it and as I couldn’t find anything related to this issue in Google, I think it is worth to share our working solution.
Problem occurs when we try to sort list of users using something like “from User u order by u.country.name desc” and sometimes country is null. In such case entities without country are simply disappearing from our result list. Longer description of this issue and how we solved it can be read below.

