我正在使用spring-data-jpa和querydsl(3.2.3)
我有一个场景,我正在根据用户filer/input创建一组谓词。所有这些来到BooleanExpression
。QueryDsl - 收集表达式中的子查询
我的简化模型看起来如下:
@Entity
public class Invoice {
@ManyToOne
private Supplier supplier;
}
@Entity
public class Supplier {
private String number;
}
@Entity
public class Company {
private String number;
private boolean active
}
现在,我与挣扎是这个查询:
SELECT * FROM Invoice WHERE invoice.supplier.number in (SELECT number from Company where active=true)
所以基本上我需要CollectionExpression
子查询一样,将获取格式所有公司都编号并将其设置为in()表达式。
我的弹簧数据存储库实现CustomQueryDslJpaRepository
,这又扩展了JpaRepository
和QueryDslPredicateExecutor
。
我希望这个答案很简单,但我对querydsl很陌生,到目前为止找不到解决方案。
似乎在QueryDSL 4中不再提供'JPASubQuery'。将此答案转换为:'BooleanExpression exp = invoice.supplier.number.in(JPAExpressions。select(公司) .where(company.active.isTrue()) .select(company.nu mber));' –
@OliverHernandez如何实现相同的Many to Mant关系? https://stackoverflow.com/questions/44830387/how-to-create-predicate-booleanexpression-for-many-to-many-relations-in-jpa –