我正在更新一個項目,以明確了解客戶,以前假設(shè)客戶,因為我們只有一個......我的問題是向 HQL 查詢添加 where 子句。我的出發(fā)點是這個查詢: public static final String SELECT_DISTINCT_STORES = "select DISTINCT e.storeNum, e.city, e.state from BoEngagement e order by e.storeNum";我想添加一個where e.customer_fk = :customer_fk子句,但每次添加 where 子句時,我都會收到各種org.hibernate.hql.internal.ast.QuerySyntaxException錯誤,除非我取出distinct關(guān)鍵字,但我不相信查詢會給出我所期望的結(jié)果。這有效: "select e.storeNum, e.city, e.state from BoEngagement e WHERE e.customer_fk = :customer_fk";而且,如果我要簡化查詢那么多,它確實應(yīng)該是"select e from BoEngagement e WHERE e.customer_fk = :customer_fk";然而,正如我所說,我不相信刪除關(guān)鍵字distinct是我想要做的。以下是我嘗試過的一些事情: "select DISTINCT e.storeNum, e.city, e.state FROM BoEngagement e WHERE e.customer_fk = :customer_fk order by e.storeNum";給出這個錯誤[ERROR] 2019-10-18 15:10:03.449 [main] BsRetrieveDistinct - java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: FROM near line 1, column 94 [SELECT DISTINCT e.city, e.state from com.bh.radar.bo.BoEngagement e order by e.state, e.city FROM com.bh.radar.bo.BoEngagement e WHERE e.customer_fk = :customer_fk]java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: FROM near line 1, column 94 [SELECT DISTINCT e.city, e.state from com.bh.radar.bo.BoEngagement e order by e.state, e.city FROM com.bh.radar.bo.BoEngagement e WHERE e.customer_fk = :customer_fk]這個更復(fù)雜的版本 "select DISTINCT e.storeNum, e.city, e.state FROM BoEngagement e in " + "(select g FROM BoEngagement g WHERE g.customer_fk = :customer_fk order by g.storeNum)";顯然我并沒有完全理解HQL和distinct關(guān)鍵字。我究竟做錯了什么?
Hibernate HQL select 與 where order by 查詢不同
慕尼黑5688855
2023-11-10 17:02:22