7
7
8
8
import java .util .Collection ;
9
9
import java .util .List ;
10
+ import java .util .Map ;
10
11
import java .util .Objects ;
11
12
import java .util .function .Consumer ;
12
13
14
+ import org .hibernate .annotations .JdbcTypeCode ;
13
15
import org .hibernate .reactive .BaseReactiveTest ;
14
16
import org .hibernate .reactive .annotations .DisabledFor ;
17
+ import org .hibernate .reactive .annotations .EnabledFor ;
18
+ import org .hibernate .type .SqlTypes ;
15
19
16
20
import org .junit .jupiter .api .Test ;
17
21
29
33
import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .DB2 ;
30
34
import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .MARIA ;
31
35
import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .ORACLE ;
36
+ import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .POSTGRESQL ;
32
37
import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .SQLSERVER ;
33
38
import static org .junit .jupiter .api .Assertions .assertEquals ;
34
39
@@ -47,6 +52,39 @@ protected Collection<Class<?>> annotatedEntities() {
47
52
return List .of ( Basic .class );
48
53
}
49
54
55
+ @ Test
56
+ @ EnabledFor (POSTGRESQL )
57
+ public void nativeQuestionMarkOperatorForPostgres (VertxTestContext context ) {
58
+ Basic basic = new Basic ();
59
+ basic .jsonAsMap = Map .of ( "sport" , "Cheese Rolling" );
60
+
61
+ test ( context , getMutinySessionFactory ()
62
+ .withTransaction ( s -> s .persist ( basic ) )
63
+ .chain ( () -> getMutinySessionFactory ().withTransaction ( s -> s
64
+ .createNativeQuery ( "select id from JsonEntity where jsonAsMap -> 'sport' \\ ? 'Cheese Rolling'" )
65
+ .getSingleResult () )
66
+ )
67
+ .invoke ( result -> assertThat ( result ).isEqualTo ( basic .id ) )
68
+ );
69
+ }
70
+
71
+ @ Test
72
+ @ EnabledFor (POSTGRESQL )
73
+ public void nativeQuestionMarkOperatorWithParameterForPostgres (VertxTestContext context ) {
74
+ Basic basic = new Basic ();
75
+ basic .jsonAsMap = Map .of ( "sport" , "Chess boxing" );
76
+
77
+ test ( context , getMutinySessionFactory ()
78
+ .withTransaction ( s -> s .persist ( basic ) )
79
+ .chain ( () -> getMutinySessionFactory ().withTransaction ( s -> s
80
+ .createNativeQuery ( "select id from JsonEntity where jsonAsMap -> 'sport' \\ ? ?" )
81
+ .setParameter ( 1 , "Chess boxing" )
82
+ .getSingleResult () )
83
+ )
84
+ .invoke ( result -> assertThat ( result ).isEqualTo ( basic .id ) )
85
+ );
86
+ }
87
+
50
88
@ Test
51
89
public void testJsonType (VertxTestContext context ) {
52
90
Basic basic = new Basic ();
@@ -92,6 +130,9 @@ private static class Basic {
92
130
93
131
private JsonObject jsonObj ;
94
132
133
+ @ JdbcTypeCode (SqlTypes .JSON )
134
+ Map <String , Object > jsonAsMap ;
135
+
95
136
public Basic () {
96
137
}
97
138
0 commit comments