QueryDsl - subquery in collection expression

后端 未结 2 653
灰色年华
灰色年华 2020-12-24 15:12

I\'m using spring-data-jpa and querydsl (3.2.3)
I have a scenario where I\'m creating set of predicates based on user filer/input. All of these comes to BooleanEx

相关标签:
2条回答
  • 2020-12-24 16:05

    Try this:

    QInvoice invoice = QInvoice.invoice;
    QCompany company = QCompany.company;
    
    List<Invoice> list = new HibernateQuery(sessionFactory.getCurrentSession())
          .from(invoice).where(
          new HibernateSubQuery().from(invoice, company).where(
                  invoice.supplier.number.eq(company.number).and(
                  company.active.eq(true))).exists()).list(invoice);
    
    0 讨论(0)
  • 2020-12-24 16:06

    Here is a variant of jaiwo99's answer in a more JPAesque form

    BooleanExpression exp = invoice.supplier.number.in(new JPASubQuery()
        .from(company)
        .where(company.active.isTrue())
        .list(company.nu‌​mber));
    

    Feel free to merge this into the original answer.

    0 讨论(0)
提交回复
热议问题