Search code examples
javaplayframeworkebean

Order by clause not working for string in Play Ebean


I want to order the list bases on string but ebean is giving an error. here is my query.

 ExpressionList<Application> query = find.query()
                .where();
 query.setFirstRow(start * 10)
                .setMaxRows(max);
 query.orderBy("applicationVerification.verificationStatus like 'PENDING%' desc");

java.lang.RuntimeException: Expecting [like] to be asc or desc?
        at io.ebean.OrderBy.isAscending(OrderBy.java:460)
        at io.ebean.OrderBy.parseProperty(OrderBy.java:445)
        at io.ebean.OrderBy.parse(OrderBy.java:414)
        at io.ebean.OrderBy.<init>(OrderBy.java:58) 

Solution

  • Like operator is used for WHERE clause and it doesn’t work for OrderBy, so you can change your code to:

     query.orderBy("applicationVerification.verificationStatus desc");
    

    or

    query.orderBy().desc("applicationVerification.verificationStatus");
    

    More info on eban site https://ebean.io/docs/query/orderBy