Search code examples
javaplayframeworkebean

Ebean sort by different date


I´d like to get a sorted list with java bean.

I got two fields in my Postgres db creation_date and update_date, I want a list sorted by whatever date is newer.

creation_date default is now(), update_date can be null

So if update_date is null the creation_date should be used as the sort value.

I want to create the following output:

created 27.12.2017 13:00

updated 27.12.2017 13:05

created 27.12.2017 14:00

created 27.12.2017 15:00

updated 27.12.2017 16:00


Solution

  • The answer was…

    List<Event> events = Ebean.find(Event.class)
                .orderBy("coalesce(update_date, creation_date) DESC")
                .findList();