diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/BaseSummary.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/BaseSummary.java new file mode 100644 index 0000000000..4a59230144 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/BaseSummary.java @@ -0,0 +1,62 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.metamodel.hhh18868; + +import jakarta.persistence.Id; +import jakarta.persistence.IdClass; +import jakarta.persistence.MappedSuperclass; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Objects; + +@IdClass(PKey.class) +@MappedSuperclass +public class BaseSummary implements Serializable { + + @Id + private Integer year; + @Id + private Integer month; + private BigDecimal value; + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public Integer getMonth() { + return month; + } + + public void setMonth(Integer month) { + this.month = month; + } + + public BigDecimal getValue() { + return value; + } + + public void setValue(BigDecimal value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if ( o == null || getClass() != o.getClass() ) { + return false; + } + BaseSummary that = (BaseSummary) o; + return Objects.equals( year, that.year ) && Objects.equals( month, that.month ); + } + + @Override + public int hashCode() { + return Objects.hash( year, month ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/HHH18868Test.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/HHH18868Test.java new file mode 100644 index 0000000000..b06c6e4113 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/HHH18868Test.java @@ -0,0 +1,34 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.metamodel.hhh18868; + +import jakarta.persistence.metamodel.SingularAttribute; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + + +import static org.assertj.core.api.Assertions.assertThat; + +@DomainModel(annotatedClasses = {Summary.class, BaseSummary.class}) +@SessionFactory +@JiraKey( "HHH-18858" ) +public class HHH18868Test { + + @Test + public void test(SessionFactoryScope scope) { + scope.inSession( entityManager -> { + final var yearAttribute = Summary_.year.getDeclaringType().getAttribute( "year" ); + assertThat( yearAttribute ).isEqualTo( Summary_.year ); + assertThat( ((SingularAttribute) yearAttribute).isId() ).isTrue(); + + final var monthAttribute = Summary_.month.getDeclaringType().getAttribute( "month" ); + assertThat( monthAttribute ).isEqualTo( Summary_.month ); + assertThat( ((SingularAttribute) monthAttribute).isId() ).isTrue(); + } ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/PKey.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/PKey.java new file mode 100644 index 0000000000..be8bb7123d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/PKey.java @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.metamodel.hhh18868; + +import java.io.Serializable; +import java.util.Objects; + +public class PKey implements Serializable { + + private Integer year; + private Integer month; + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public Integer getMonth() { + return month; + } + + public void setMonth(Integer month) { + this.month = month; + } + + @Override + public boolean equals(Object o) { + if ( o == null || getClass() != o.getClass() ) { + return false; + } + PKey pKey = (PKey) o; + return Objects.equals( year, pKey.year ) && Objects.equals( month, pKey.month ); + } + + @Override + public int hashCode() { + return Objects.hash( year, month ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/Summary.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/Summary.java new file mode 100644 index 0000000000..ef0d0849d4 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/Summary.java @@ -0,0 +1,11 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.metamodel.hhh18868; + +import jakarta.persistence.Entity; + +@Entity +public class Summary extends BaseSummary { +}