Skip to content

Commit be25511

Browse files
cigalymbellade
authored andcommitted
HHH-18868 Adapted test case from https://hibernate.atlassian.net/browse/HHH-18868
1 parent c88b1e8 commit be25511

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.metamodel.hhh18868;
6+
7+
import jakarta.persistence.Id;
8+
import jakarta.persistence.IdClass;
9+
import jakarta.persistence.MappedSuperclass;
10+
11+
import java.io.Serializable;
12+
import java.math.BigDecimal;
13+
import java.util.Objects;
14+
15+
@IdClass(PKey.class)
16+
@MappedSuperclass
17+
public class BaseSummary implements Serializable {
18+
19+
@Id
20+
private Integer year;
21+
@Id
22+
private Integer month;
23+
private BigDecimal value;
24+
25+
public Integer getYear() {
26+
return year;
27+
}
28+
29+
public void setYear(Integer year) {
30+
this.year = year;
31+
}
32+
33+
public Integer getMonth() {
34+
return month;
35+
}
36+
37+
public void setMonth(Integer month) {
38+
this.month = month;
39+
}
40+
41+
public BigDecimal getValue() {
42+
return value;
43+
}
44+
45+
public void setValue(BigDecimal value) {
46+
this.value = value;
47+
}
48+
49+
@Override
50+
public boolean equals(Object o) {
51+
if ( o == null || getClass() != o.getClass() ) {
52+
return false;
53+
}
54+
BaseSummary that = (BaseSummary) o;
55+
return Objects.equals( year, that.year ) && Objects.equals( month, that.month );
56+
}
57+
58+
@Override
59+
public int hashCode() {
60+
return Objects.hash( year, month );
61+
}
62+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.metamodel.hhh18868;
6+
7+
import jakarta.persistence.metamodel.SingularAttribute;
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.JiraKey;
10+
import org.hibernate.testing.orm.junit.SessionFactory;
11+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
12+
import org.junit.jupiter.api.Test;
13+
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
@DomainModel(annotatedClasses = {Summary.class, BaseSummary.class})
18+
@SessionFactory
19+
@JiraKey( "HHH-18858" )
20+
public class HHH18868Test {
21+
22+
@Test
23+
public void test(SessionFactoryScope scope) {
24+
scope.inSession( entityManager -> {
25+
final var yearAttribute = Summary_.year.getDeclaringType().getAttribute( "year" );
26+
assertThat( yearAttribute ).isEqualTo( Summary_.year );
27+
assertThat( ((SingularAttribute<?, ?>) yearAttribute).isId() ).isTrue();
28+
29+
final var monthAttribute = Summary_.month.getDeclaringType().getAttribute( "month" );
30+
assertThat( monthAttribute ).isEqualTo( Summary_.month );
31+
assertThat( ((SingularAttribute<?, ?>) monthAttribute).isId() ).isTrue();
32+
} );
33+
}
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.metamodel.hhh18868;
6+
7+
import java.io.Serializable;
8+
import java.util.Objects;
9+
10+
public class PKey implements Serializable {
11+
12+
private Integer year;
13+
private Integer month;
14+
15+
public Integer getYear() {
16+
return year;
17+
}
18+
19+
public void setYear(Integer year) {
20+
this.year = year;
21+
}
22+
23+
public Integer getMonth() {
24+
return month;
25+
}
26+
27+
public void setMonth(Integer month) {
28+
this.month = month;
29+
}
30+
31+
@Override
32+
public boolean equals(Object o) {
33+
if ( o == null || getClass() != o.getClass() ) {
34+
return false;
35+
}
36+
PKey pKey = (PKey) o;
37+
return Objects.equals( year, pKey.year ) && Objects.equals( month, pKey.month );
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
return Objects.hash( year, month );
43+
}
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.metamodel.hhh18868;
6+
7+
import jakarta.persistence.Entity;
8+
9+
@Entity
10+
public class Summary extends BaseSummary {
11+
}

0 commit comments

Comments
 (0)