0

I have a java entity PullRequest which has Comments, Reviewers, and Labels associations. I'm using older version of hibernate 3.5.0-Final.

I have an API getPullRequests which should return List<PullRequest>. How can I fetch PullRequests using join fetch so that I can get Comments, Reviewers and Labels in 3 join queries instead of using N+1 queries.

I tried using distinct join fetch like select distinct p from PullRequest join fetch p.Comments where p.id in (:prids)

It is throwing BLOB can't be used in select distinct.

How can I fetch all associations using join fetch so that it won't trigger N+1 queries.

Sudhakar B
  • 1,465
  • 9
  • 16
  • Does this answer your question? [How to use multiple JOIN FETCH in one JPQL query](https://stackoverflow.com/questions/30088649/how-to-use-multiple-join-fetch-in-one-jpql-query) – SternK Nov 27 '20 at 08:05
  • Tried that approach, in the hibernate version I have mentioned,`QueryHints.PASS_DISTINCT_THROUGH` is not available. – Sudhakar B Nov 27 '20 at 08:54
  • `QueryHints.PASS_DISTINCT_THROUGH` is just query optimization that by the way broken in the newest hibernate version. – SternK Nov 27 '20 at 08:56
  • yeah, but without it, it will fetch duplicate PullRequest instances as it has joins if my understanding is correct. – Sudhakar B Nov 27 '20 at 09:10
  • You can still use `distinct` in jpql, and it will work as expected. The only side effect the query will not be so optimal as with the `QueryHints.PASS_DISTINCT_THROUGH` hint. – SternK Nov 27 '20 at 09:31
  • I tried that also, it is throwing BLOB can't be used on select in the hibernate version I'm using. – Sudhakar B Nov 27 '20 at 11:06

0 Answers0