Aaron Gadberry

Help – v. helped, help·ing, helps

Was this site helpful?
My Amazon.com Wishlist

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.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>