2009-06-09 17 views
-2

によって私は休止状態のためにHQLで書かれたクエリを次のようしています。HQL注文クエリ与える問題

============================================== ==========================

select new map(ret.retailerDesc as ret_name, ret.id.retailerId as ret_id, 
       ret.id.serviceId as service_id, 

(select count(distinct i.inspectionId) as inspections from Inspection i 
inner join i.clgCodeStatus c 
inner join c.retailerOrderses r 
inner join r.cusRetailer cr 
inner join i.inspectionMission m where ret.id = cr.id ) as inspections , 

(select count(distinct i.inspectionId) as inspections from Inspection i 
inner join i.clgCodeStatus c 
inner join c.retailerOrderses r 
inner join r.cusRetailer cr 
inner join i.inspectionMission m 
where ret.id = cr.id and i.inspectionResult = '1' ) as match, 

(select count(distinct i.inspectionId) as inspections from Inspection i 
inner join i.clgCodeStatus c 
inner join c.retailerOrderses r 
inner join r.cusRetailer cr 
inner join i.inspectionMission m 
where ret.id = cr.id and i.inspectionResult = '0' ) as mismatch ) 

from CusRetailer ret order by inspections desc 

================= ==========================================

ERROR: column "inspections" does not exist 

それは「査察DESCによってオーダー」のため、このエラーを与えている:====クエリ上記

は、それが次のエラーを与える実行します。 削除すると正常に動作します。

誰もがこの問題を解決するために私を助けてくださいことはできますか?

ありがとうございました。

+0

amar4kintu

こんにちは、 あなたは(あなたはHibernateがtrueにshow_sqlプロパティを設定することにより、これを印刷することができます)HibernateはこのHQLクエリの生成SQLを表示することができます。 Hibernateは不平を言っているようなエラーから はそれが見えませんが、あなたのデータベースがあります。 乾杯お返事 –

答えて

0

上記のクエリで「order by col_1_0_」を使って解決しました。hibernateはcol_0_0_、col_1_0_、col_2_0_という名前の列を作成するため、解決します。列の順序を知り、したがってによって順番..

感謝。

+1

これは良い "解決策"ですか?あなたは、クエリの先頭に列を追加する場合、間違った列を指すように起こっていることにより、ご注文(または他のいくつかの変更の原因は、何らかの方法で列の順序を変更するために休止状態ならば)。 [これは、順序を使用して人を壊すのと同じコンセプトです(たとえば、「ORDER BY 1」)(http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/06/bad-habits-to-kick- order-by-ordinal.aspx)。確かにすべての栄光で冬眠は、このハックよりも良い解決策を持っています。私はGarethの提案を好まない。 –

2

それはあなたがそれはHQLはorder by句で式をサポートしていない、あなたの代わりに、n個のSQLクエリを使用する必要があることかもしれinspections

...from CusRetailer ret order by count(distinct i.inspectionId) 

ための表現を繰り返す必要がある場合があります。