JOIN FETCH for nested lazy OneToOne

Hi.

I have an entity structure as follows:

E1
    List<E2> e2s; //is lazy embeddable

E2
    E3 e3; // is lazy one-to-one

E3

So I’m able to “pre-fetch” e2s by:

SELECT e1 
FROM E1 e1
JOIN FETCH e1.e2s AS e2Alias

But I also need to “prefetch” the e2.e3. If I try to do something like:

SELECT e1 
FROM E1 e1
JOIN FETCH e1.e2s AS e2Alias
JOIN FETCH e2Alias.e3

I’m getting:

query specified join fetching, but the owner of the fetched association was not present in the select list

As I understand JOIN FETCH is for collections.

In case of

SELECT e1 
FROM E1 e1
JOIN FETCH e1.e2s AS e2Alias
JOIN e2Alias.e3

It generates correct join part but doesn’t use result in the SELECT part in the generated SQL

What todo in case of one-to-one?

Which Hibernate version are you using? There was a bug in the past that prevented to join fetch an association of a collection element.

Sorry my bad. We are using the 5.3.10.Final-redhat-00001

You are probably affected by this [HHH-14609] Fetch join association within fetched element collection fails - Hibernate JIRA

Yes, it looks so. Will need to retest it after fix in some release. For now just changed fetch mode to eager.