Skip to content

Commit e931a80

Browse files
committed
HHH-15520 Add test for issue
1 parent 228eabe commit e931a80

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package org.hibernate.orm.test.annotations.various;
2+
3+
import org.hibernate.annotations.Generated;
4+
import org.hibernate.annotations.GenerationTime;
5+
import org.hibernate.annotations.Subselect;
6+
7+
import org.hibernate.testing.TestForIssue;
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.junit.jupiter.api.Test;
12+
13+
import jakarta.persistence.Column;
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.Id;
16+
import jakarta.persistence.JoinColumn;
17+
import jakarta.persistence.OneToOne;
18+
import jakarta.persistence.PrimaryKeyJoinColumn;
19+
import jakarta.persistence.Table;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
23+
@DomainModel(
24+
annotatedClasses = {
25+
OneOneGeneratedValueTest.EntityB.class,
26+
OneOneGeneratedValueTest.EntityA.class
27+
}
28+
)
29+
@SessionFactory
30+
@TestForIssue(jiraKey = "HHH-15520")
31+
public class OneOneGeneratedValueTest {
32+
33+
@Test
34+
public void testIt(SessionFactoryScope scope) {
35+
scope.inTransaction(
36+
session -> {
37+
EntityA entityA = new EntityA( 1l );
38+
session.persist( entityA );
39+
}
40+
);
41+
scope.inTransaction(
42+
session -> {
43+
EntityA entityA = session.get( EntityA.class, 1l );
44+
assertThat( entityA ).isNotNull();
45+
EntityB entityB = entityA.getB();
46+
assertThat( entityB ).isNotNull();
47+
assertThat( entityB.getB() ).isEqualTo( 5l );
48+
}
49+
);
50+
}
51+
52+
@Entity(name = "EntityA")
53+
@Table(name = "TABLE_A")
54+
public static class EntityA {
55+
56+
@Id
57+
private Long id;
58+
59+
private String name;
60+
61+
@Generated(GenerationTime.INSERT)
62+
@OneToOne(mappedBy = "a")
63+
private EntityB b;
64+
65+
public EntityA() {
66+
}
67+
68+
public EntityA(Long id) {
69+
this.id = id;
70+
}
71+
72+
public Long getId() {
73+
return id;
74+
}
75+
76+
public EntityB getB() {
77+
return b;
78+
}
79+
}
80+
81+
@Entity(name = "EntityB")
82+
@Subselect("SELECT 5 as b, a.id AS AId FROM TABLE_A a")
83+
public static class EntityB {
84+
85+
private Long aId;
86+
87+
private EntityA a;
88+
89+
private Long b;
90+
91+
@Id
92+
public Long getAId() {
93+
return aId;
94+
}
95+
96+
public void setAId(Long aId) {
97+
this.aId = aId;
98+
}
99+
100+
@OneToOne
101+
@PrimaryKeyJoinColumn
102+
public EntityA getA() {
103+
return a;
104+
}
105+
106+
public void setA(EntityA a) {
107+
this.a = a;
108+
}
109+
110+
public Long getB() {
111+
return b;
112+
}
113+
114+
public void setB(Long b) {
115+
this.b = b;
116+
}
117+
118+
119+
}
120+
}

0 commit comments

Comments
 (0)