子查询作为querydsl中的字段

时间:2014-05-23 09:22:52

标签: inheritance subquery querydsl

我遇到了一些问题。

我想使用querydsl根据SQL编写子查询。

SQL(ps:v_task_recipient是一个视图。)

select v.title, v.create_date_time from v_task_recipient v where (select r.branch_id from tbl_recipient r where v.recipient_id = r.id) in (2704230,2703041,2702932);

在java部分,我这样写:

List<Branch> branches = user.getBranchesForPermissionOperation(Operations.claim_update);

    ListSubQuery<Branch> subquery =  new JPASubQuery().from(branchRecipient).where(taskRecipentView.recipient_id.eq(branchRecipient.id)).list(branchRecipient.branch);
    for(Branch branch: branches)
    {
        ex = ex == null ? subquery.contains(branch) : ex.or(subquery.contains(branch)); 
    }

有没有更好的解决方案来避免丑陋的for循环?我可以在&#39;中使用某些表达式吗?

,最困难的部分是branchRecipient继承自父收件人。

private static QRecipient recipient = QRecipient.recipient;
private static QBranchRecipient branchRecipient = recipient.as(QBranchRecipient.class);
private static QUserRecipient userRecipient = recipient.as(QUserRecipient.class);

它总是导致异常

  

java.lang.IllegalArgumentException:未声明的路径&#39;收件人&#39;。将此路径添加为查询的源以便能够引用它。

0 个答案:

没有答案