File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
hibernate-reactive-core/src/test/java/org/hibernate/reactive Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,25 @@ private static String nameFromResult(List<Object> rowSet) {
56
56
}
57
57
}
58
58
59
+ @ Test
60
+ public void sessionClear (TestContext context ) {
61
+ final GuineaPig guineaPig = new GuineaPig ( 81 , "Perry" );
62
+ test (
63
+ context ,
64
+ getMutinySessionFactory ().withSession ( session -> session
65
+ .persist ( guineaPig )
66
+ .invoke ( session ::clear )
67
+ // If the previous clear doesn't work, this will cause a duplicated entity exception
68
+ .chain ( () -> session .persist ( guineaPig ) )
69
+ .call ( session ::flush )
70
+ .chain ( () -> session .createQuery ( "FROM GuineaPig" , GuineaPig .class )
71
+ // By not using .find() we check that there is only one entity in the db with getSingleResult()
72
+ .getSingleResult () )
73
+ .invoke ( result -> assertThatPigsAreEqual ( context , guineaPig , result ) )
74
+ )
75
+ );
76
+ }
77
+
59
78
@ Test
60
79
public void reactiveWithTransactionStatelessSession (TestContext context ) {
61
80
final GuineaPig guineaPig = new GuineaPig ( 61 , "Mr. Peanutbutter" );
Original file line number Diff line number Diff line change @@ -76,6 +76,25 @@ public void reactiveFind(TestContext context) {
76
76
);
77
77
}
78
78
79
+ @ Test
80
+ public void sessionClear (TestContext context ) {
81
+ final GuineaPig guineaPig = new GuineaPig ( 81 , "Perry" );
82
+ test (
83
+ context ,
84
+ getSessionFactory ().withSession ( session -> session
85
+ .persist ( guineaPig )
86
+ .thenAccept ( v -> session .clear () )
87
+ // If the previous clear doesn't work, this will cause a duplicated entity exception
88
+ .thenCompose ( v -> session .persist ( guineaPig ) )
89
+ .thenCompose ( v -> session .flush () )
90
+ .thenCompose ( v -> session .createQuery ( "FROM GuineaPig" , GuineaPig .class )
91
+ // By not using .find() we check that there is only one entity in the db with getSingleResult()
92
+ .getSingleResult () )
93
+ .thenAccept ( result -> assertThatPigsAreEqual ( context , guineaPig , result ) )
94
+ )
95
+ );
96
+ }
97
+
79
98
@ Test
80
99
public void reactiveWithTransactionSession (TestContext context ) {
81
100
final GuineaPig guineaPig = new GuineaPig ( 61 , "Mr. Peanutbutter" );
You can’t perform that action at this time.
0 commit comments