|
4 | 4 | */ |
5 | 5 | package org.hibernate.orm.test.lazyload; |
6 | 6 |
|
7 | | -import java.io.Serializable; |
8 | | -import java.util.ArrayList; |
9 | | -import java.util.List; |
10 | | -import jakarta.persistence.Column; |
11 | | -import jakarta.persistence.Entity; |
12 | | -import jakarta.persistence.FetchType; |
13 | | -import jakarta.persistence.GeneratedValue; |
14 | | -import jakarta.persistence.Id; |
15 | | -import jakarta.persistence.JoinColumn; |
16 | | -import jakarta.persistence.ManyToOne; |
17 | | -import jakarta.persistence.OneToMany; |
18 | | -import jakarta.persistence.OneToOne; |
19 | 7 |
|
20 | 8 | import org.hibernate.Hibernate; |
21 | 9 | import org.hibernate.cfg.Environment; |
|
29 | 17 | import org.junit.jupiter.api.BeforeEach; |
30 | 18 | import org.junit.jupiter.api.Test; |
31 | 19 |
|
32 | | -import static org.hamcrest.CoreMatchers.is; |
33 | | -import static org.hamcrest.MatcherAssert.assertThat; |
34 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; |
35 | 21 | import static org.junit.jupiter.api.Assertions.assertFalse; |
36 | 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
41 | 27 | @DomainModel( |
42 | 28 | annotatedClasses = { |
43 | 29 | Parent.class, |
44 | | - Child.class, |
45 | | - LazyLoadingTest.Client.class, |
46 | | - LazyLoadingTest.Address.class, |
47 | | - LazyLoadingTest.Account.class |
| 30 | + Child.class |
48 | 31 | } |
49 | 32 | ) |
50 | 33 | @SessionFactory |
@@ -110,182 +93,4 @@ public void testLazyCollectionLoadingAfterEndTransaction(SessionFactoryScope sco |
110 | 93 | assertEquals( CHILDREN_SIZE, j ); |
111 | 94 | } |
112 | 95 |
|
113 | | - @Test |
114 | | - @JiraKey(value = "HHH-11838") |
115 | | - public void testGetIdOneToOne(SessionFactoryScope scope) { |
116 | | - final Object clientId = scope.fromTransaction( |
117 | | - session -> { |
118 | | - Address address = new Address(); |
119 | | - session.persist( address ); |
120 | | - Client client = new Client( address ); |
121 | | - session.persist( client ); |
122 | | - return client.getId(); |
123 | | - } |
124 | | - ); |
125 | | - |
126 | | - final Long addressId = scope.fromTransaction( |
127 | | - session -> { |
128 | | - Client client = session.get( Client.class, clientId ); |
129 | | - Address address = client.getAddress(); |
130 | | - address.getId(); |
131 | | - assertThat( Hibernate.isInitialized( address ), is( true ) ); |
132 | | - address.getStreet(); |
133 | | - assertThat( Hibernate.isInitialized( address ), is( true ) ); |
134 | | - return address.getId(); |
135 | | - } |
136 | | - ); |
137 | | - |
138 | | - scope.inTransaction( session -> { |
139 | | - Address address = session.get( Address.class, addressId ); |
140 | | - Client client = address.getClient(); |
141 | | - client.getId(); |
142 | | - assertThat( Hibernate.isInitialized( client ), is( false ) ); |
143 | | - client.getName(); |
144 | | - assertThat( Hibernate.isInitialized( client ), is( true ) ); |
145 | | - } ); |
146 | | - } |
147 | | - |
148 | | - protected boolean rebuildSessionFactoryOnError() { |
149 | | - return false; |
150 | | - } |
151 | | - |
152 | | - @Test |
153 | | - @JiraKey(value = "HHH-11838") |
154 | | - public void testGetIdManyToOne(SessionFactoryScope scope) { |
155 | | - Serializable accountId = scope.fromTransaction( session -> { |
156 | | - Address address = new Address(); |
157 | | - session.persist( address ); |
158 | | - Client client = new Client( address ); |
159 | | - Account account = new Account(); |
160 | | - client.addAccount( account ); |
161 | | - session.persist( account ); |
162 | | - session.persist( client ); |
163 | | - return account.getId(); |
164 | | - } ); |
165 | | - |
166 | | - scope.inTransaction( |
167 | | - session -> { |
168 | | - Account account = session.getReference( Account.class, accountId ); |
169 | | - Client client = account.getClient(); |
170 | | - client.getId(); |
171 | | - assertThat( Hibernate.isInitialized( client ), is( false ) ); |
172 | | - client.getName(); |
173 | | - assertThat( Hibernate.isInitialized( client ), is( true ) ); |
174 | | - } ); |
175 | | - |
176 | | - } |
177 | | - |
178 | | - @Entity(name = "Account") |
179 | | - public static class Account { |
180 | | - @Id |
181 | | - @GeneratedValue |
182 | | - private Long id; |
183 | | - |
184 | | - @ManyToOne(fetch = FetchType.LAZY) |
185 | | - @JoinColumn(name = "id_client") |
186 | | - private Client client; |
187 | | - |
188 | | - public Client getClient() { |
189 | | - return client; |
190 | | - } |
191 | | - |
192 | | - public Long getId() { |
193 | | - return id; |
194 | | - } |
195 | | - |
196 | | - public void setId(Long id) { |
197 | | - this.id = id; |
198 | | - } |
199 | | - |
200 | | - public void setClient(Client client) { |
201 | | - this.client = client; |
202 | | - } |
203 | | - } |
204 | | - |
205 | | - @Entity(name = "Address") |
206 | | - public static class Address { |
207 | | - @Id |
208 | | - @GeneratedValue |
209 | | - private Long id; |
210 | | - |
211 | | - @Column |
212 | | - private String street; |
213 | | - |
214 | | - @OneToOne(fetch = FetchType.LAZY) |
215 | | - @JoinColumn(name = "id_client") |
216 | | - private Client client; |
217 | | - |
218 | | - public String getStreet() { |
219 | | - return street; |
220 | | - } |
221 | | - |
222 | | - public void setStreet(String street) { |
223 | | - this.street = street; |
224 | | - } |
225 | | - |
226 | | - public Long getId() { |
227 | | - return id; |
228 | | - } |
229 | | - |
230 | | - public void setId(Long id) { |
231 | | - this.id = id; |
232 | | - } |
233 | | - |
234 | | - public Client getClient() { |
235 | | - return client; |
236 | | - } |
237 | | - |
238 | | - public void setClient(Client client) { |
239 | | - this.client = client; |
240 | | - } |
241 | | - } |
242 | | - |
243 | | - @Entity(name = "Client") |
244 | | - public static class Client { |
245 | | - @Id |
246 | | - @GeneratedValue |
247 | | - private Long id; |
248 | | - |
249 | | - @Column |
250 | | - private String name; |
251 | | - |
252 | | - @OneToMany(mappedBy = "client") |
253 | | - private List<Account> accounts = new ArrayList<>(); |
254 | | - |
255 | | - @OneToOne(mappedBy = "client", fetch = FetchType.LAZY) |
256 | | - private Address address; |
257 | | - |
258 | | - public Client() { |
259 | | - } |
260 | | - |
261 | | - public Client(Address address) { |
262 | | - this.address = address; |
263 | | - address.setClient( this ); |
264 | | - } |
265 | | - |
266 | | - public void addAccount(Account account) { |
267 | | - accounts.add( account ); |
268 | | - account.setClient( this ); |
269 | | - } |
270 | | - |
271 | | - public String getName() { |
272 | | - return name; |
273 | | - } |
274 | | - |
275 | | - public Long getId() { |
276 | | - return id; |
277 | | - } |
278 | | - |
279 | | - public void setId(Long id) { |
280 | | - this.id = id; |
281 | | - } |
282 | | - |
283 | | - public Address getAddress() { |
284 | | - return address; |
285 | | - } |
286 | | - |
287 | | - public void setAddress(Address address) { |
288 | | - this.address = address; |
289 | | - } |
290 | | - } |
291 | 96 | } |
0 commit comments