简体   繁体   English

休眠查询未返回零值

[英]Hibernate query not returning Zero value

Same query working in SQL 在SQL中使用相同查询

Select count(tbl_leads.lead_Status_Id) , tbl_LeadStatus.LeadStatus_Type FROM tbl_LeadStatus LEFT JOIN tbl_leads ON tbl_LeadStatus.LeadStatus_id = tbl_leads.lead_Status_Id GROUP BY tbl_LeadStatus.LeadStatus_Type;

Hibernate Query 休眠查询

Select s.LeadStatus_Type, count(l.status) FROM Status s "
                + "LEFT JOIN Lead l ON l.status = s.LeadStatus_id "
                + "GROUP BY s.LeadStatus_Type"

Expecting output is this 期望的输出是这个

   Count  LeadStatus_Type
    '0'   'Cancelled' 
    '0'   'In-Progress' 
    '1'   'New' 
    '0'   'Sold' 
    '0'   'UnAssigned' 

And HQL return this 和HQL返回此

'1', 'New' 

Your join condition looks off. 您的加入条件看起来很差。 In HQL we join from an entity to the other entity which exists as a property of the first entity. 在HQL中,我们从一个实体连接到另一个实体,该实体作为第一个实体的属性存在。 Most importantly, there is no ON clause as that relationship is already known within Hibernate. 最重要的是,因为在Hibernate中已经知道该关系,所以没有ON子句。 Try the following: 请尝试以下操作:

SELECT s.LeadStatus_Type, COUNT(l.status)
FROM Status s
LEFT JOIN s.LeadStatus_id l
GROUP BY s.LeadStatus_Type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM