Issue
I am using spring boot specification and trying to order a set of results by name such that names that start with "ca" come first. The query looks like -
order by name like 'ca%' desc
I have used the code
cq.orderBy(cb.desc(cb.like(root.get("name"), value + "%")));
However, I land me into an error
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: like near
Solution
Figured it out. All I had to do was to add these 2 lines of code
Expression<Object> queryCase = cb.selectCase().when(cb.like(root.get(NAME), value + "%"), 0).otherwise(1);
cq.orderBy(cb.asc(queryCase));
Answered By - Tapan