You are here: Basics Operations & Concepts > Querying > Native Queries > Native Query Sorting

Native Query Sorting

Native Query syntax allows you to specify a comparator, which will be used to sort the results:

final ObjectSet<Pilot> pilots = container.query(new Predicate<Pilot>() {
    @Override
    public  boolean match(Pilot o) {
        return o.getAge() > 18;
    }
}, new QueryComparator<Pilot>() {
    public  int compare(Pilot pilot, Pilot pilot1) {
        return pilot.getName().compareTo(pilot1.getName());
    }
});
NativeQueriesSorting.java: Native query with sorting