2

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!

1 Answer 1

2

No you can't (according to the spec).

Note that Hibernate supports it though.

Sign up to request clarification or add additional context in comments.

1 Comment

The answer referred to here is about multiple concatenated joins, e.g. entity A has an attribute referring to entity B which in turn has an attribute referring to an entity C. A -> B -> C. The question here is about multiple joins from the same starting entity, so A -> B and A -> C, which is something very different. The documentation quoted in that answer does not disallow the intention of the OP.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.