Search code examples
javahibernatesortingbooleanhibernate-criteria

How are Booleans sorted?


I am sorting with the following code:

undoneCategories = session.createCriteria(Category.class);
undoneCategories.add(Restrictions.eq("Done", false));
undoneCategories.addOrder(Order.asc("UpwardGenerator"));
undoneCategories.setMaxResults(1);

where UpwardGenerator is boolean.

How will it be sorted? With false first, or with true first? What about null/nil/undefined values?


Solution

  • It will sort false first, since in the database true and false are represented as 1 and 0, respectively.