UnknownTableReferenceException when selecting entity using IdClass

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 (JIRA ticket). 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.

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

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.