diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/CompositeIdAttributeAccessTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/CompositeIdAttributeAccessTests.java index 547cb276530a..02e52c3c2b11 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/CompositeIdAttributeAccessTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/CompositeIdAttributeAccessTests.java @@ -14,6 +14,7 @@ import jakarta.persistence.metamodel.EntityType; import jakarta.persistence.metamodel.SingularAttribute; import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.Jira; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.junit.jupiter.api.Test; @@ -81,6 +82,50 @@ private void checkIdClassType(EmbeddableType idClassType) { assertThat( key2Attribute.getJavaMember().getDeclaringClass() ).isEqualTo( AnEntity.PK.class ); } + @Test + @Jira("https://hibernate.atlassian.net/browse/HHH-12996") + @DomainModel(annotatedClasses = {BasicEntity.class, IdClassEntity.class, IdClassEntity.PK.class, NestedIdClassEntity.class, NestedIdClassEntity.PK.class, AnEntity.PK.class, AnEntity.class, AnotherEntity.class}) + @SessionFactory + void testQuery(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + session.createQuery( "select a.idClassEntity.basicEntity.key1 from NestedIdClassEntity a" ).getResultList(); + session.createQuery( "select a.idClassEntity.basicEntity.name from NestedIdClassEntity a" ).getResultList(); + + session.createQuery( "select a.key2.id from AnEntity a" ).getResultList(); + session.createQuery( "select a.key2.name from AnEntity a" ).getResultList(); + } ); + } + + @Entity(name = "BasicEntity") + public static class BasicEntity { + @Id Long key1; + String name; + } + + @Entity(name = "IdClassEntity") + @IdClass( IdClassEntity.PK.class ) + public static class IdClassEntity { + @Id @ManyToOne BasicEntity basicEntity; + @Id Long key2; + + public static class PK implements Serializable { + Long basicEntity; + Long key2; + } + } + + @Entity(name = "NestedIdClassEntity") + @IdClass( NestedIdClassEntity.PK.class ) + public static class NestedIdClassEntity { + @Id @ManyToOne IdClassEntity idClassEntity; + @Id Long key3; + + public static class PK implements Serializable { + IdClassEntity.PK idClassEntity; + Long key3; + } + } + @Entity(name="AnEntity") @Table(name="entity_a") @IdClass(AnEntity.PK.class)