Use NULLS FIRST in TOPLink Expression API Ordering
22nd January 2008 - By Aaron Gadberry
There is no specific method for NULLS FIRST (default is NULLS LAST), but you can still accomplish this through the expression api.
You can simply append some sql to the end of your ordering field expression and it will take care of it for you.
For example, if you are ordering by the name then this would put the nulls last (default):
query.addOrdering(builder.get("name"));
This code could be ammended into the following to put nulls first:
query.addOrdering(builder.get("name").postfixSQL("NULLS FIRST"));
It’s that easy.