Skip to content

Commit

Permalink
HHH-12996 - Property paths for associations that are part of the enti…
Browse files Browse the repository at this point in the history
…ty ID (i.e. IdClass) are not initialized
  • Loading branch information
sebersole committed Nov 19, 2024
1 parent 6707dee commit 26ed1e2
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,50 @@ private void checkIdClassType(EmbeddableType<AnEntity.PK> 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)
Expand Down

0 comments on commit 26ed1e2

Please sign in to comment.