Reputation: 11
Update : Solution found. Problem was somewhere else in my code.
I'm using Ebean with Play Framework and I'm stuck with a query witch as orderBy clause on two columns. The first column is a varchar and the second one is a datetime.
The problem is when I add the second column in the orderBy clause, I can't sort anymore on the first one.
I have tried with the Ebean query way and the RawSQL way but the problem is still here.
Here are the lines of code I have tried :
Ebean.createQuery(NavGav.class).where().in("account.itemState", Account.getActiveStates()).between("navGavDate", "2015-01-01 00:00:00", "2015-12-31 23:59:59").orderBy(orderBy + " " + sort + ", navGavDate").findPagingList(ITEM_BY_PAGE * 12);
RawSql :
select columns
from nav_gav t0 left outer join account t1 on t1.id = t0.account_id where t1.item_state in ('VALIDATED', 'PENDING_DEACTIVATION', 'UPDATED')
order By t0.nav_frequency desc , t0.nav_gav_date
The query works on phpMyAdmin but not in the application.
Can you tell me what am I doing wrong?
Thanks.
Upvotes: 1
Views: 1366
Reputation: 261
Please try not to concatenate the ordeyBy(column)
method. try this.
Ebean.createQuery(NavGav.class)
.where().in("account.itemState", Account.getActiveStates())
.between("navGavDate", "2015-01-01 00:00:00", "2015-12-31 23:59:59")
.orderBy(orderBy + " " + sort)
.orderBy(navGavDate + " " + sort)
.findPagingList(ITEM_BY_PAGE * 12);
Upvotes: 1