5

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.

6
  • I deleted my "answer". I just tried, and similar query with as deep level of join fetches seems to work (Hibernate 3.5.6). Commented Oct 5, 2011 at 17:49
  • Hi Mikko Maunu,thanks for your effort. Did you try using associations with collections or just OneToOne associations? and How many queries it generated ? just want to know... Commented Oct 6, 2011 at 13:43
  • Hi, with @OneToMany Set<Ent[1-6]>, six levels: SELECT DISTINCT e FROM Ent1 e LEFT JOIN FETCH e.entities e2 LEFT JOIN FETCH e2. entities e3 LEFT JOIN .... Commented Oct 7, 2011 at 7:09
  • looks like issue mentioned here:hibernate.onjira.com/browse/HHH-4935 I have bidirectional oneToOne association between identifier and singerIdentifier. I changed it to manyToOne & oneToMany, and it is generating just one query now. Commented Oct 13, 2011 at 17:07
  • Can you write the SQL query being generated on console for this HQL ? Commented Jan 10, 2013 at 13:57

1 Answer 1

1

Maybe a typo?

 left join fetch i.identifierReportedAreas -->ira<-- left join fetch -->irc<---.reportedArea ra 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.