# JOIN FETCH for nested lazy OneToOne

**URL:** <https://discourse.hibernate.org/t/join-fetch-for-nested-lazy-onetoone/5478>\
**Category:** Hibernate ORM\
**Created:** [June 22, 2021, 8:31pm UTC](https://discourse.hibernate.org/t/join-fetch-for-nested-lazy-onetoone/5478 "2021-06-22T20:31:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andriy\_Ch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/andriy_ch/32/1566_2.png) [@Andriy\_Ch](https://discourse.hibernate.org/u/Andriy_Ch)\
**Post date:** [June 22, 2021, 8:31pm UTC](https://discourse.hibernate.org/t/join-fetch-for-nested-lazy-onetoone/5478/1 "2021-06-22T20:31:35Z")

</div>

Hi.

I have an entity structure as follows:

```auto
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:

```auto
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:

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

```

I’m getting:

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [June 24, 2021, 7:35am UTC](https://discourse.hibernate.org/t/join-fetch-for-nested-lazy-onetoone/5478/2 "2021-06-24T07:35:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andriy\_Ch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/andriy_ch/32/1566_2.png) [@Andriy\_Ch](https://discourse.hibernate.org/u/Andriy_Ch)\
**Post date:** [June 24, 2021, 8:00am UTC](https://discourse.hibernate.org/t/join-fetch-for-nested-lazy-onetoone/5478/3 "2021-06-24T08:00:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [June 24, 2021, 10:03am UTC](https://discourse.hibernate.org/t/join-fetch-for-nested-lazy-onetoone/5478/4 "2021-06-24T10:03:59Z")

</div>

You are probably affected by this [[HHH-14609] Fetch join association within fetched element collection fails - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-14609)

---

<div class="post-metadata">

**Author:** ![Andriy\_Ch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/andriy_ch/32/1566_2.png) [@Andriy\_Ch](https://discourse.hibernate.org/u/Andriy_Ch)\
**Post date:** [June 24, 2021, 5:56pm UTC](https://discourse.hibernate.org/t/join-fetch-for-nested-lazy-onetoone/5478/5 "2021-06-24T17:56:20Z")

</div>

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