14
14
import org .hibernate .annotations .Fetch ;
15
15
import org .hibernate .annotations .FetchMode ;
16
16
17
+ import org .junit .After ;
17
18
import org .junit .Test ;
18
19
19
20
import io .vertx .ext .unit .TestContext ;
@@ -42,6 +43,13 @@ protected Collection<Class<?>> annotatedEntities() {
42
43
return List .of ( Element .class , Node .class );
43
44
}
44
45
46
+ @ After
47
+ public void cleanDb (TestContext context ) {
48
+ test ( context , getSessionFactory ()
49
+ .withTransaction ( s -> s .createQuery ( "delete from Element" ).executeUpdate ()
50
+ .thenCompose ( v -> s .createQuery ( "delete from Node" ).executeUpdate () ) ) );
51
+ }
52
+
45
53
@ Test
46
54
public void testQuery (TestContext context ) {
47
55
Node basik = new Node ( "Child" );
@@ -52,23 +60,21 @@ public void testQuery(TestContext context) {
52
60
basik .parent .elements .add ( new Element ( basik .parent ) );
53
61
basik .parent .elements .add ( new Element ( basik .parent ) );
54
62
55
- test (
56
- context ,
57
- openSession ()
58
- .thenCompose ( s -> s .persist ( basik ).thenCompose ( v -> s .flush () ) )
63
+ test ( context , getSessionFactory ()
64
+ .withTransaction ( s -> s .persist ( basik ) )
59
65
.thenCompose ( v -> openSession () )
60
66
.thenCompose ( s -> s .createQuery ( "from Node n order by id" , Node .class )
61
67
.getResultList ()
62
68
.thenCompose ( list -> {
63
69
context .assertEquals ( list .size (), 2 );
64
70
Node n1 = list .get ( 0 );
65
71
Node n2 = list .get ( 1 );
66
- context .assertFalse ( Hibernate .isInitialized ( n1 .elements ) );
67
- context .assertFalse ( Hibernate .isInitialized ( n2 .elements ) );
68
- return s .fetch ( n1 .elements ).thenAccept ( elements -> {
72
+ context .assertFalse ( Hibernate .isInitialized ( n1 .getElements () ) );
73
+ context .assertFalse ( Hibernate .isInitialized ( n2 .getElements () ) );
74
+ return s .fetch ( n1 .getElements () ).thenAccept ( elements -> {
69
75
context .assertTrue ( Hibernate .isInitialized ( elements ) );
70
- context .assertTrue ( Hibernate .isInitialized ( n1 .elements ) );
71
- context .assertTrue ( Hibernate .isInitialized ( n2 .elements ) );
76
+ context .assertTrue ( Hibernate .isInitialized ( n1 .getElements () ) );
77
+ context .assertTrue ( Hibernate .isInitialized ( n2 .getElements () ) );
72
78
} );
73
79
} )
74
80
)
@@ -91,6 +97,22 @@ public Element(Node node) {
91
97
92
98
Element () {
93
99
}
100
+
101
+ public Integer getId () {
102
+ return id ;
103
+ }
104
+
105
+ public void setId (Integer id ) {
106
+ this .id = id ;
107
+ }
108
+
109
+ public Node getNode () {
110
+ return node ;
111
+ }
112
+
113
+ public void setNode (Node node ) {
114
+ this .node = node ;
115
+ }
94
116
}
95
117
96
118
@ Entity (name = "Node" )
@@ -209,5 +231,85 @@ public boolean equals(Object o) {
209
231
public int hashCode () {
210
232
return Objects .hash ( string );
211
233
}
234
+
235
+ public Integer getVersion () {
236
+ return version ;
237
+ }
238
+
239
+ public void setVersion (Integer version ) {
240
+ this .version = version ;
241
+ }
242
+
243
+ public Node getParent () {
244
+ return parent ;
245
+ }
246
+
247
+ public void setParent (Node parent ) {
248
+ this .parent = parent ;
249
+ }
250
+
251
+ public List <Element > getElements () {
252
+ return elements ;
253
+ }
254
+
255
+ public void setElements (List <Element > elements ) {
256
+ this .elements = elements ;
257
+ }
258
+
259
+ public boolean isPrePersisted () {
260
+ return prePersisted ;
261
+ }
262
+
263
+ public void setPrePersisted (boolean prePersisted ) {
264
+ this .prePersisted = prePersisted ;
265
+ }
266
+
267
+ public boolean isPostPersisted () {
268
+ return postPersisted ;
269
+ }
270
+
271
+ public void setPostPersisted (boolean postPersisted ) {
272
+ this .postPersisted = postPersisted ;
273
+ }
274
+
275
+ public boolean isPreUpdated () {
276
+ return preUpdated ;
277
+ }
278
+
279
+ public void setPreUpdated (boolean preUpdated ) {
280
+ this .preUpdated = preUpdated ;
281
+ }
282
+
283
+ public boolean isPostUpdated () {
284
+ return postUpdated ;
285
+ }
286
+
287
+ public void setPostUpdated (boolean postUpdated ) {
288
+ this .postUpdated = postUpdated ;
289
+ }
290
+
291
+ public boolean isPostRemoved () {
292
+ return postRemoved ;
293
+ }
294
+
295
+ public void setPostRemoved (boolean postRemoved ) {
296
+ this .postRemoved = postRemoved ;
297
+ }
298
+
299
+ public boolean isPreRemoved () {
300
+ return preRemoved ;
301
+ }
302
+
303
+ public void setPreRemoved (boolean preRemoved ) {
304
+ this .preRemoved = preRemoved ;
305
+ }
306
+
307
+ public boolean isLoaded () {
308
+ return loaded ;
309
+ }
310
+
311
+ public void setLoaded (boolean loaded ) {
312
+ this .loaded = loaded ;
313
+ }
212
314
}
213
315
}
0 commit comments