SqmAttributeJoin not yet resolved to TableGroup

After upgrading Hibernate from 5.x to 6.x, the following query results in error “SqmAttributeJoin not yet resolved to TableGroup”:

select a from A a join treat(a.sub as Sub) i join i.x ix join B b on b.x=ix

public class A {
   private Set<Super> sub;
   @OneToMany(mappedBy = "a")
   public Set<Super> getSub() {}
}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
@DiscriminatorValue("any")
@Table(name = "Super")
public class Super {
  private A a;
  @ManyToOne
  @JoinColumn(name = "aId", nullable = false)
  public A getA() {}
}
@Entity
@DiscriminatorValue("sub")
public class Sub extends Super {
  private X x;
  @ManyToOne(optional = false)
  @JoinColumn(name = "xId")
  public X getX() {}
}

Hello @Harald_Ueland, we’re going to need a lot more information to try and help you understand what’s going on. On what Hibernate version are you seeing this bug? Can you please share the full stack trace?

The mappings and the query you posted look fine to me, so if this error still occurs with Hibernate’s latest stable version, please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a new ticket in our issue tracker and attach that reproducer.

Hi @mbladel, and thank you for the reply.

We’re using Wildfly 32.0.1.Final with Hibernate 6.4.4. Here is the stack trace:

Caused by: org.hibernate.query.sqm.InterpretationException: Error interpreting query [SqmAttributeJoin not yet resolved to TableGroup]
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQualifiedAttributeJoin(BaseSqmToSqlAstConverter.java:3970)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQualifiedAttributeJoin(BaseSqmToSqlAstConverter.java:440)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.SemanticQueryWalker.visitSingularJoin(SemanticQueryWalker.java:216)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.tree.domain.SqmSingularJoin.accept(SqmSingularJoin.java:49)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitComparisonPredicate(BaseSqmToSqlAstConverter.java:7528)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitComparisonPredicate(BaseSqmToSqlAstConverter.java:440)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate.accept(SqmComparisonPredicate.java:111)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitNestedTopLevelPredicate(BaseSqmToSqlAstConverter.java:7140)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.consumeEntityJoin(BaseSqmToSqlAstConverter.java:3485)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.consumeExplicitJoin(BaseSqmToSqlAstConverter.java:3240)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.consumeJoins(BaseSqmToSqlAstConverter.java:2888)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.consumeFromClauseRoot(BaseSqmToSqlAstConverter.java:2822)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.tree.from.SqmFromClause.visitRoots(SqmFromClause.java:80)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitFromClause(BaseSqmToSqlAstConverter.java:2573)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQuerySpec(BaseSqmToSqlAstConverter.java:2055)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQuerySpec(BaseSqmToSqlAstConverter.java:440)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.tree.select.SqmQuerySpec.accept(SqmQuerySpec.java:127)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.spi.BaseSemanticQueryWalker.visitQueryPart(BaseSemanticQueryWalker.java:218)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitQueryPart(BaseSqmToSqlAstConverter.java:1915)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelectStatement(BaseSqmToSqlAstConverter.java:1600)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitSelectStatement(BaseSqmToSqlAstConverter.java:440)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.tree.select.SqmSelectStatement.accept(SqmSelectStatement.java:228)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.translate(BaseSqmToSqlAstConverter.java:776)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.buildCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:402)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:327)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:303)
        at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:509)
        at org.hibernate@6.4.4.Final//org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:427)
        at org.hibernate@6.4.4.Final//org.hibernate.query.Query.getResultList(Query.java:120)

Also tested same query with Hibernate 6.6.1, and got same error.

Changing query to

select a from A a join treat(a.sub as Sub) i join B b on b.x=i.x

works as expected, so I believe that the problem is this join:

join i.x ix

If the issue persists in 6.6.1 create a Jira issue and attach a reproducer so that someone might look into it.