# UnknownTableReferenceException when selecting entity using IdClass

**URL:** <https://discourse.hibernate.org/t/unknowntablereferenceexception-when-selecting-entity-using-idclass/7427>\
**Category:** Hibernate ORM\
**Created:** [March 24, 2023, 12:19pm UTC](https://discourse.hibernate.org/t/unknowntablereferenceexception-when-selecting-entity-using-idclass/7427 "2023-03-24T12:19:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_De\_Mol](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/robin_de_mol/32/2338_2.png) [@Robin\_De\_Mol](https://discourse.hibernate.org/u/Robin_De_Mol)\
**Post date:** [March 24, 2023, 12:19pm UTC](https://discourse.hibernate.org/t/unknowntablereferenceexception-when-selecting-entity-using-idclass/7427/1 "2023-03-24T12:19:35Z")

</div>

When migration from Hibernate 5 to 6, some of our existing queries broke unexpectedly. I’ve been able to pinpoint the issue and create a reproducer, which can be found [here](https://github.com/hibernate/hibernate-test-case-templates/pull/256) ([JIRA ticket](https://hibernate.atlassian.net/browse/HHH-16366)). I’ve seen a handful of similar topics on these boards, but they all seem sufficiently different to merit starting a new discussion.

The issue occurs when modelling a many-to-many relation with three entities, using `@IdClass` on the entity that represents the relation itself. A JPQL query that used to work in Hibernate 5 now throws an exception and I’ve found that removing the join fetch results in no exception being thrown, though I figure that’s more of a workaround than a solution.

I hope the reproducer is sufficient and if not, I’m more than happy to supply whatever information is needed to resolve this issue.

---

<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:** [March 24, 2023, 12:32pm UTC](https://discourse.hibernate.org/t/unknowntablereferenceexception-when-selecting-entity-using-idclass/7427/2 "2023-03-24T12:32:46Z")

</div>

Thanks. We’ll discuss the topic on the JIRA issue if we have further questions.

---

<div class="post-metadata">

**Author:** ![Robin\_De\_Mol](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/robin_de_mol/32/2338_2.png) [@Robin\_De\_Mol](https://discourse.hibernate.org/u/Robin_De_Mol)\
**Post date:** [March 24, 2023, 2:52pm UTC](https://discourse.hibernate.org/t/unknowntablereferenceexception-when-selecting-entity-using-idclass/7427/3 "2023-03-24T14:52:37Z")

</div>

Thanks @beikov. Small addendum: I’ve since discovered that downgrading to 6.1.7 also allows the original query to succeed. So the issue must lie somewhere in the 6.2 changes.
