Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA Hibernate left join fetch generating mutiple queries

I have a jpql query to eagerly fetch multi level associations as follows

  select distinct s from Singer s
  left join fetch s.singerIdentifiers si  //singerIdentifiers is collection in Singer object
  left join fetch si.identifier i
  left join fetch i.identifierReportedAreas ira
  left join fetch irc.reportedArea ra
  left join fetch rc.reportingSystem rs
  where s.id in (?);

This generates multiples queries, though I am getting all the required information in the first select itself. All extra queries are for querying SingerIdentifier table data for distinct IdentifierIds from the first query.

Any help in this regard is highly appreciated.

like image 544
user877016 Avatar asked Nov 14 '22 16:11

user877016


1 Answers

Maybe a typo?

  left join fetch i.identifierReportedAreas -->ira<--
  left join fetch -->irc<---.reportedArea ra
like image 82
KoW Avatar answered Jan 27 '23 22:01

KoW