ClassCastException in Hibernate 6 when "join fetch" is used in a query with entity inheritance

em.createQuery("select e from " + Entity1.class.getSimpleName() + " e left join fetch e.subClass1 left join fetch e.subClass2 ", Entity1.class).getSingleResult()

This query used to work in Hibernate 5, but I’m getting the following error in Hibernate 6:

Exception in thread “main” java.lang.ClassCastException: class org.example.entity.SubClass1 cannot be cast to class org.example.entity.SubClass2 (org.example.entity.SubClass1 and org.example.entity.SubClass2 are in unnamed module of loader ‘app’)

@Entity
@Getter
@Setter
public class Entity1 {
    @Id
    String id;

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "entity1")
    protected SubClass1 subClass1;

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "entity1")
    protected SubClass2 subClass2;
}
@Entity
@Getter
@Setter
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class SuperClass implements Serializable {
    @Id
    public String id;

    @ManyToOne
    protected Entity1 entity1;
}
@Entity
@DiscriminatorValue("1")
public class SubClass1 extends SuperClass {
}
@Entity
@DiscriminatorValue("2")
public class SubClass2 extends SuperClass {
}

Try updating to 6.2.4.Final. If the problem persists, please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) that reproduces the issue.