简体   繁体   English

使用join子句的hql查询不起作用的“ where”限制

[英]“where” restrictions not working on hql query with join clause

First of all clarify that I am quite bad with databases, so please do not be to mean with my code :P 首先要弄清楚我对数据库非常不好,所以请不要对我的代码:P

I have a problem with a query on hibernate using join and restrictions. 我对使用联接和限制的休眠查询有问题。 I have a huge list of Assignments and some of them have an Asr object. 我有大量的Assignments清单,其中一些具有Asr对象。

queryString.append("select new commons.bo.assignment.AssignmentAssociateExtract("
    + " assignment.id, assignment.contract.assignmentStatus,"
    + " assignment.contract.beginDate, assignment.contract.endDate,"
    + " assignment.contract.contractType, assignment.organizationalData.homeCountryKey,"
    + " assignment.organizationalData.hostCountryKey," 
    + " assignment.organizationalData.homeOrgUnitKey,"
    + " assignment.associate.globalIdAssociate,"
    + " assignment.associate.localIdHome,"
    + " assignment.associate.firstName,"
    + " assignment.associate.lastName)"
    + " from Assignment assignment left join assignment.asr asr"
    + " where assignment.contract.assignmentStatus.code = 5"
    + " and asr.homeAsrElegibility is not 'X'"
    + " or asr.homeAsrElegibility is null"
);

I was creating this query step by step. 我正在逐步创建此查询。 Before I created it without the join clause left join assignment.asr asr and it was working well but of course it was not showing the Assignments that did not have a Asr object. 在没有连接子句的情况下创建它之前, left join assignment.asr asrleft join assignment.asr asr ,它运行良好,但当然不会显示没有Asr对象的Assignments After I added the join clause, now it shows every single Assignment (10.000 records when those who have an assignmentStatus = 5 are just 4.000) and the restrictions like 在我添加了join子句之后,现在它显示了每个单独的Assignment (当那些assignmentStatus = 5的记录仅为4.000时,记录为10.000条记录),以及类似

where assignment.contract.assignmentStatus.code = 5

are not reflected in the result anymore. 不再反映在结果中。

So to sum up: I need a list with all assignments with assignmentStatus = 5 and asr.homeAsrElegibility != 'X'. 综上所述:我需要一个包含所有分配的列表,其中所有赋值的值为assignmentStatus = 5且asr.homeAsrElegibility!='X'。 But it needs to include also all assignments with assignmentStatus = 5 even if they do not have an Asr object. 但是,即使它们没有Asr对象,也需要包括所有带有assignmentStatus = 5的分配。

Any ideas?? 有任何想法吗?? Thanks! 谢谢!

Parenthesis helps to clarify the situation. 括号有助于弄清情况。

queryString.append("select new commons.bo.assignment.AssignmentAssociateExtract("
    + " assignment.id, assignment.contract.assignmentStatus,"
    + " assignment.contract.beginDate, assignment.contract.endDate,"
    + " assignment.contract.contractType, assignment.organizationalData.homeCountryKey,"
    + " assignment.organizationalData.hostCountryKey," 
    + " assignment.organizationalData.homeOrgUnitKey,"
    + " assignment.associate.globalIdAssociate,"
    + " assignment.associate.localIdHome,"
    + " assignment.associate.firstName,"
    + " assignment.associate.lastName)"
    + " from Assignment assignment left join assignment.asr asr"
    + " where assignment.contract.assignmentStatus.code = 5"
    + " and ((asr.homeAsrElegibility is not null and asr.homeAsrElegibility is not 'X')"
    + " or (asr.homeAsrElegibility is null))"
);

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

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