第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Hibernate HQL select 與 where order by 查詢不同

Hibernate HQL select 與 where order by 查詢不同

慕尼黑5688855 2023-11-10 17:02:22
我正在更新一個項目,以明確了解客戶,以前假設(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)鍵字。我究竟做錯了什么?
查看完整描述

1 回答

?
一只名叫tom的貓

TA貢獻(xiàn)1906條經(jīng)驗 獲得超3個贊

研究 EntityManager.createNativeQuery 方法,并提出這個有效的 PostgreSQL 查詢:

??public?static?final?String?SELECT_DISTINCT_STORES?=
?????????"SELECT?DISTINCT?ON(storeNum,?city,?state)?*?FROM?radar2.engagement?WHERE?customer_fk?=?:customer_fk?ORDER?BY?storeNum?asc,?city,?state";

我這樣使用它:

????results?=?em.createNativeQuery(SELECT_DISTINCT_CITY_STATES,?BoEngagement.class)
????????????????.setParameter("customer_fk",?customer_fk)
????????????????.getResultList();

現(xiàn)在,這個解決方案特定于 PostgreSQL,但這是我現(xiàn)在和無限期的未來使用的數(shù)據(jù)庫。


查看完整回答
反對 回復(fù) 2023-11-10
  • 1 回答
  • 0 關(guān)注
  • 312 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號