Reputation: 100
I'm trying to get the data from 3 tables in one query. I have "Workexperiences", "Skills" and "Descriptions". The idea is that one Workexperience has multiple Skills related to it and multiple Descriptions. I'm trying to query all the Workexperiences from one perticular Employer (the Workexperience table has an "EmployerId" column).
I started with fetching the descriptions, this works:
select distinct w from Workexperience w
left join fetch w.skills
where w.employer=(select e from Employer e where e.username = :username)
This gives me all the Workexperiences with their skills, so far so good. When I try to add the Descriptions, it goes bad:
select distinct w from Workexperience as w
left join fetch w.skills
left join fetch w.descriptions
where w.employer=(select e from Employer e where e.username = :username)
This gives me the classic lazyinitializationexception.
So my question is: can you use multiple 'left join fetch' statements in one query? And if so, how do you do this?
Thanks in advance!
Upvotes: 2
Views: 6339