Skip to content

Commit 728e2d0

Browse files
committed
HHH-18608 Add test for issue
1 parent 9071c16 commit 728e2d0

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package org.hibernate.orm.test.refresh;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.hibernate.annotations.BatchSize;
7+
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+
12+
import org.junit.jupiter.api.BeforeEach;
13+
14+
import jakarta.persistence.CascadeType;
15+
import jakarta.persistence.Column;
16+
import jakarta.persistence.Entity;
17+
import jakarta.persistence.FetchType;
18+
import jakarta.persistence.GeneratedValue;
19+
import jakarta.persistence.Id;
20+
import jakarta.persistence.JoinColumn;
21+
import jakarta.persistence.ManyToOne;
22+
import jakarta.persistence.OneToMany;
23+
import jakarta.persistence.OneToOne;
24+
import jakarta.persistence.Table;
25+
26+
@DomainModel(
27+
annotatedClasses = {
28+
RefreshUninitializedAssociationsTest.User.class,
29+
RefreshUninitializedAssociationsTest.UserInfo.class,
30+
RefreshUninitializedAssociationsTest.Phone.class,
31+
}
32+
)
33+
@SessionFactory
34+
public class RefreshUninitializedAssociationsTest {
35+
36+
@BeforeEach
37+
public void setUp(SessionFactoryScope scope) {
38+
scope.inTransaction(
39+
session -> {
40+
41+
}
42+
);
43+
}
44+
45+
@Entity(name = "User")
46+
@Table(name = "USER_TABLE")
47+
@BatchSize(size = 5)
48+
public static class User {
49+
50+
@Id
51+
@GeneratedValue
52+
private long id;
53+
54+
@Column
55+
private String name;
56+
57+
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
58+
@JoinColumn(name = "INFO_ID", referencedColumnName = "ID")
59+
private UserInfo info;
60+
61+
public User() {
62+
}
63+
64+
public User(long id, String name, UserInfo info) {
65+
this.id = id;
66+
this.name = name;
67+
this.info = info;
68+
info.user = this;
69+
}
70+
71+
public long getId() {
72+
return id;
73+
}
74+
75+
public String getName() {
76+
return name;
77+
}
78+
79+
public UserInfo getInfo() {
80+
return info;
81+
}
82+
}
83+
84+
@Entity(name = "UserInfo")
85+
public static class UserInfo {
86+
@Id
87+
@GeneratedValue
88+
private long id;
89+
90+
@OneToOne(mappedBy = "info", fetch = FetchType.LAZY)
91+
private User user;
92+
93+
private String info;
94+
95+
@OneToMany(mappedBy = "info", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
96+
private List<Phone> phoneList = new ArrayList<>();
97+
98+
public long getId() {
99+
return id;
100+
}
101+
102+
public UserInfo(long id, String info) {
103+
this.id = id;
104+
this.info = info;
105+
}
106+
107+
public User getUser() {
108+
return user;
109+
}
110+
111+
public String getInfo() {
112+
return info;
113+
}
114+
115+
public List<Phone> getPhoneList() {
116+
return phoneList;
117+
}
118+
119+
public void addPhone(Phone phone) {
120+
this.phoneList.add(phone);
121+
phone.setInfo(this);
122+
}
123+
}
124+
125+
@Entity(name = "Phone")
126+
public static class Phone {
127+
@Id
128+
private String number;
129+
130+
@ManyToOne
131+
@JoinColumn(name = "INFO_ID")
132+
private UserInfo info;
133+
134+
public String getNumber() {
135+
return number;
136+
}
137+
138+
public void setNumber(String number) {
139+
this.number = number;
140+
}
141+
142+
public UserInfo getInfo() {
143+
return info;
144+
}
145+
146+
public void setInfo(UserInfo info) {
147+
this.info = info;
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)