Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order seems not work when orderByClause has expression #3516

Open
xu1009 opened this issue Oct 31, 2024 · 2 comments
Open

order seems not work when orderByClause has expression #3516

xu1009 opened this issue Oct 31, 2024 · 2 comments

Comments

@xu1009
Copy link

xu1009 commented Oct 31, 2024

orderByClause is CASE
WHEN (cc IN ('1','2','3','4')
or dd in ('1','2','3','4')) and ( array_contains(qq,'5') ) THEN 1
else 5
END;

the error is

ava.lang.RuntimeException: Expecting [and] to be asc or desc? at io.ebean.OrderBy.isAscending(OrderBy.java:446) at io.ebean.OrderBy.parseProperty(OrderBy.java:432) at io.ebean.OrderBy.parse(OrderBy.java:401) at io.ebean.OrderBy.(OrderBy.java:56) at io.ebeaninternal.server.querydefn.DefaultOrmQuery.orderBy(DefaultOrmQuery.java:1626) at io.ebean.Query.order(Query.java:1383) at io.ebean.typequery.TQRootBean.order(TQRootBean.java:1295) at

the orderByClause has comma

@rPraml
Copy link
Contributor

rPraml commented Oct 31, 2024

Can you try orderBy().asc(yourString)?
Note: ebean tries to do a simple parsing when you set the orderBy statement. Normally you would specify a comma separated list of properties. So complex expressions might not work.
If your sort expression is constant, you might define a @Formula(select=yourExpression) property in your model and just sort on that property. Ebean will then substitute the query fragment. (Of course this is a workaround and makes only sense, if your formula is constant. Keep in mind that you may need additional annotations like specifiing FetchType.LAZY)
Roland

@xu1009
Copy link
Author

xu1009 commented Nov 1, 2024

thx, orderBy().asc(yourString) it works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants