我遇到了一个 SQL 问题。
假设这是我的原生 SQL:
SELECT * FROM products
ORDER BY balance <= bottleneck DESC, product_code ASC
这是在 postgressql 工作的。但它不适用于 HQL。我的 HQL 如下:
from Products as p order by p.balance < p.bottleneck desc, p.productCode asc
我遇到了以下异常:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: < near line 1, column 67 [from com.inventory.inventory.vo.Products as p order by p.balance < p.bottleneck]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
at com.inventory.inventory.dao.impl.ProductsDAOImpl.getProducts(ProductsDAOImpl.java:72)
at Main.main(Main.java:43)
有什么办法可以解决这个查询吗?
非常感谢您的帮助。
谢谢,最好的 rgds,A1ucard