Java – querydsl – subquery in set expression
•
Java
I use spring data JPA and querydsl (3.2.3)
My simplified model is as follows:
@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 }
Now, what I'm trying to do is this query:
SELECT * FROM Invoice WHERE invoice.supplier.number in (SELECT number from Company where active=true)
So basically, I need to make a sub query in the collectionexpression, such as format, to get all the company numbers and set them as an in () expression
My spring database implements customquerydsljparepository, which extends jparepository and querydslpredicateexecutor I hope the answer is straightforward, but I'm new to querydsl and haven't found a solution so far
Solution
This is a variant of jaiwo99, more in the form of jpaesque
BooleanExpression exp = invoice.supplier.number.in(new JPASubQuery() .from(company) .where(company.active.isTrue()) .list(company.number));
Randomly merge them into the original answer
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码