Select by attribute of composity key of child entity

I have an issue with a criteria query in Spring Boot 3.1.2 (Hibernate 6.2.6).

Description of Mapping

Assuming we have two entities EntityA and EntityB. EntityA has a simple integer ID as primary key. EntityB has a composite key, consisting of one related EntityA and a string. Given by the mapping, there can be multiple entities B for one entity A (n:1).

The following diagram shows the entities, their attributes, and the relationship between them:

Criteria Query

We want to build a criteria query to select all Entities A, which have a relationship with an EntityB that have a specific value in the string attribute of their composite key.

For that, we use the following (exemplary) query:

final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<EntityA> cq = cb.createQuery(EntityA.class);
final Root<EntityA> entityARoot = cq.from(EntityA.class);
final ListJoin<EntityA, EntityB> entityBJoin = entityARoot.join(EntityA_.entitiesB);




When executing the query, I get the following exception:

org.hibernate.sql.ast.SqlTreeCreationException: Could not locate TableGroup - com.example.demo.EntityA(10532809360900).entitiesB(10532811315300).{element}.key

	at org.hibernate.sql.ast.spi.FromClauseAccess.getTableGroup(
	at org.hibernate.query.sqm.sql.internal.BasicValuedPathInterpretation.from(
	at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.lambda$visitBasicValuedPath$49(
	at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.prepareReusablePath(

Does anybody know if there is something wrong with our mapping or query? Or is this a Hibernate issue?

It is worth mentioning that working with the entities (e.g., retrieved by the repository classes) works well and as expected.

This looks like a bug. Please create an issue in the issue tracker( with a test case( that reproduces the issue.

Thank you for your reply. I created the issue.