When building a Predicate for the Entity Book, I would like to be able to left join on Category (ManyToMany) to add a AND Predicate on Category. I could simply achieve that if I have the JPAQuery instance :
if (catId != null) {
jpaQuery.leftJoin(book.categories, category);
jpaQuery.where(category.id.eq(catId).or(category.parentCategory.id.eq(catId)));
}
But when building Predicates I don't have yet the JPAQuery. So for the Predicate itself I could do :
booleanBuilder.and(category.id.eq(this.categoryId).or(category.parentCategory.id.eq(this.categoryId)));
But for the leftjoin how to proceed without the jpaQuery instance ?
You need the Query to declare the left join in Querydsl. If this is Spring Data related, they might come up with an API level solution.
book.categories.any() can be used instead of category, but it is serialized differently to JPQL, with a subquery instead of a join.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With