Skip to content

Commit 1f7628b

Browse files
committed
fix up test
1 parent 728e2d0 commit 1f7628b

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed
Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import java.util.List;
55

66
import org.hibernate.annotations.BatchSize;
7+
import org.hibernate.cfg.AvailableSettings;
78

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-
9+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
10+
import org.hibernate.testing.orm.junit.JiraKey;
11+
import org.hibernate.testing.orm.junit.Jpa;
12+
import org.hibernate.testing.orm.junit.Setting;
1213
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
1315

1416
import jakarta.persistence.CascadeType;
1517
import jakarta.persistence.Column;
@@ -23,21 +25,41 @@
2325
import jakarta.persistence.OneToOne;
2426
import jakarta.persistence.Table;
2527

26-
@DomainModel(
28+
@Jpa(
2729
annotatedClasses = {
28-
RefreshUninitializedAssociationsTest.User.class,
29-
RefreshUninitializedAssociationsTest.UserInfo.class,
30-
RefreshUninitializedAssociationsTest.Phone.class,
30+
RefreshAndBatchTest.User.class,
31+
RefreshAndBatchTest.UserInfo.class,
32+
RefreshAndBatchTest.Phone.class,
33+
},
34+
properties = {
35+
@Setting(name = AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, value = "100")
36+
3137
}
3238
)
33-
@SessionFactory
34-
public class RefreshUninitializedAssociationsTest {
39+
@JiraKey("HHH-18608")
40+
public class RefreshAndBatchTest {
3541

3642
@BeforeEach
37-
public void setUp(SessionFactoryScope scope) {
43+
public void setUp(EntityManagerFactoryScope scope) {
3844
scope.inTransaction(
3945
session -> {
46+
UserInfo info = new UserInfo( "info" );
47+
Phone phone = new Phone( "123456" );
48+
info.addPhone( phone );
49+
User user = new User( 1l, "user1", info );
50+
session.persist( user );
51+
}
52+
);
53+
}
4054

55+
@Test
56+
public void testRefresh(EntityManagerFactoryScope scope) {
57+
scope.inTransaction(
58+
session -> {
59+
User user = session.createQuery( "select u from User u where u.id = :id", User.class )
60+
.setParameter( "id", 1l )
61+
.getSingleResult();
62+
session.refresh( user.getInfo() );
4163
}
4264
);
4365
}
@@ -48,8 +70,7 @@ public void setUp(SessionFactoryScope scope) {
4870
public static class User {
4971

5072
@Id
51-
@GeneratedValue
52-
private long id;
73+
private Long id;
5374

5475
@Column
5576
private String name;
@@ -85,22 +106,24 @@ public UserInfo getInfo() {
85106
public static class UserInfo {
86107
@Id
87108
@GeneratedValue
88-
private long id;
109+
private Long id;
89110

90111
@OneToOne(mappedBy = "info", fetch = FetchType.LAZY)
91112
private User user;
92113

93114
private String info;
94115

95-
@OneToMany(mappedBy = "info", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
96-
private List<Phone> phoneList = new ArrayList<>();
116+
@OneToMany(mappedBy = "info", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
117+
private List<Phone> phoneList;
97118

98119
public long getId() {
99120
return id;
100121
}
101122

102-
public UserInfo(long id, String info) {
103-
this.id = id;
123+
public UserInfo() {
124+
}
125+
126+
public UserInfo(String info) {
104127
this.info = info;
105128
}
106129

@@ -117,8 +140,11 @@ public List<Phone> getPhoneList() {
117140
}
118141

119142
public void addPhone(Phone phone) {
120-
this.phoneList.add(phone);
121-
phone.setInfo(this);
143+
if ( phoneList == null ) {
144+
phoneList = new ArrayList<>();
145+
}
146+
this.phoneList.add( phone );
147+
phone.info = this;
122148
}
123149
}
124150

@@ -131,20 +157,19 @@ public static class Phone {
131157
@JoinColumn(name = "INFO_ID")
132158
private UserInfo info;
133159

134-
public String getNumber() {
135-
return number;
160+
public Phone() {
136161
}
137162

138-
public void setNumber(String number) {
163+
public Phone(String number) {
139164
this.number = number;
140165
}
141166

142-
public UserInfo getInfo() {
143-
return info;
167+
public String getNumber() {
168+
return number;
144169
}
145170

146-
public void setInfo(UserInfo info) {
147-
this.info = info;
171+
public UserInfo getInfo() {
172+
return info;
148173
}
149174
}
150175
}

0 commit comments

Comments
 (0)