0

i am trying to query the following data using querydsl. All works fine except the OneToMany properties like review.criteria.

I need to leftjoin the review.criteria where review.id equals to criterion.review.id, so i suppose i need to use a subquery in leftjoin.

By default querydsl / jpa does not support this. Any idea how to do this?

Here is the code:

BlazeJPAQuery<Review> reviewJPAQuery = new BlazeJPAQuery<Tuple>(entityManager, cbf)
        .select(review).from(review)
        .leftJoin(review.configElement, configElement).fetchJoin()
        .leftJoin(configElement.node, node).fetchJoin()
        .leftJoin(node.project, project).fetchJoin()
        .leftJoin(review.milestone, milestone).fetchJoin()
        .leftJoin(review.criteria, criterion).fetchJoin()
        .where(globalReviewsFilter)
        .orderBy(orderSpecifiers);

As a note, i implemented also blaze persistence because it's supposed that it supports subqueries in joins, but the documentation confuses me. The joins are done more or less in from clause, that in my case doesn't help much.

bullgr
  • 21
  • 1
  • 3
  • Not quite sure what you mean or why you need a subquery at all - if review has a OneToMany defined to Criteria, doesn't it already have this join defined? What are you after above and beyond that join? What isn't working exactly? Do you maybe mean the join itself to a *ToMany is a problem and you want to load the relationship separate from the main query - if so, see the BatchSize annotation docs – Chris Feb 21 '23 at 19:39
  • Please share the mappings you are using and maybe also a HQL form of what you are looking for. If `Review#criteria` is `@OneToMany(mappedBy = "review")` and `Criterion#review` is `@ManyToOne`, then the join will naturally already use the join condition you described. – Christian Beikov Feb 27 '23 at 12:23

0 Answers0