HQL通过查询给出问题的顺序 [英] HQL Order by query giving problem

查看:228
本文介绍了HQL通过查询给出问题的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HQL中为Hibernate编写了以下查询。



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

 选择新地图(ret.retailerDesc为ret_name,ret.id.retailerId为ret_id,
ret.id. serviceId作为service_id,

(select count(distinct i.inspectionId))作为检查的检查i
内部连接i.clgCodeStatus c
内部连接c.retailerOrderses r
内部连接r.cusRetailer cr
内部连接i.inspectionMission m,其中ret.id = cr.id)作为检查,

(选择计数(不同的i.inspectionId)作为Inspection i的检查
内连接i.clgCodeStatus c
内连接c.retailerOrderses r
内连接r.cusRetailer cr
内连接i.inspectionMission m
其中ret.id = cr .id和i.inspectionResult ='1')作为匹配,

(选择计数(不同的i.inspectionId)作为检查的检查i
内部连接i.clgCodeStatus c
内连接c.retailerOrderses r
内连接r.cusRetailer cr
内连接i.inspectionMission m
其中ret.id = cr.id和i.inspectionResult ='0' )as mismatch)

from CusRetailer ret order by inspections desc

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



执行上面的查询时,会出现以下错误:

 错误:列检查不存在

它给出了按检验顺序排序的错误。
如果我删除它可以正常工作。



任何人都可以帮我解决这个问题吗?

感谢。

解决方案

我在上面的查询中使用order by col_1_0_解决了这个问题..因为hibernate创建了名为col_0_0_ ,col_1_0_,col_2_0_等等..所以如果你只是需要知道你的列的顺序,并相应地添加它来订购..



谢谢。



amar4kintu


I have following query written in HQL for Hibernate.

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

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

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

When above query executes it gives following error:

ERROR: column "inspections" does not exist

It is giving this error for "order by inspections desc". If I remove that it works fine.

Can anyone please help me to resolve this problem?

Thanks.

解决方案

I solved it using "order by col_1_0_" in above query.. because hibernate creates column with names col_0_0_, col_1_0_, col_2_0_ and so on.. so if you just need to know the order of your column and add it to order by accordingly..

Thanks.

amar4kintu

这篇关于HQL通过查询给出问题的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆