I have the following query (using jpa 2.0):
String query = "
SELECT p.id, p.name
FROM package p
ORDER BY (p.id = :idPackage) DESC, (p.mPrice+p.vPrice) DESC
LIMIT 10 ";
query.setParameter("idPackage", idPackage);
query.getResultList();
where package has the following attributes:
Package
- id
- name
- mPrice
- vPrice
- duration
In the JPA query, when I try to execute it, it complains about the “=” operator in ORDER BY clause. Is there any way to get around it ??
This is the exception I get:
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node:
You cannot use ‘=’ in
order byclause with JPA Queries. If you really need that, you can usecreateNativeQueryinsteadcreateQuery.