4
4
*/
5
5
package org .hibernate .orm .test .mapping .hhh17404 ;
6
6
7
- import jakarta .persistence .Access ;
8
- import jakarta .persistence .AccessType ;
9
7
import jakarta .persistence .Embeddable ;
10
8
import jakarta .persistence .Entity ;
11
9
import jakarta .persistence .Id ;
12
10
import jakarta .persistence .Table ;
13
11
import org .hibernate .annotations .JdbcTypeCode ;
14
12
import org .hibernate .cfg .DialectSpecificSettings ;
15
13
import org .hibernate .dialect .OracleDialect ;
16
- import org .hibernate .orm .test .mapping .basic .JsonMappingTests ;
17
14
import org .hibernate .testing .orm .junit .DomainModel ;
18
15
import org .hibernate .testing .orm .junit .RequiresDialect ;
19
16
import org .hibernate .testing .orm .junit .ServiceRegistry ;
20
17
import org .hibernate .testing .orm .junit .SessionFactory ;
21
18
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
22
19
import org .hibernate .testing .orm .junit .Setting ;
23
20
import org .hibernate .type .SqlTypes ;
24
- import org .junit .jupiter .api .AfterEach ;
25
21
import org .junit .jupiter .api .BeforeEach ;
26
22
import org .junit .jupiter .api .Test ;
27
23
32
28
33
29
import static org .hamcrest .MatcherAssert .assertThat ;
34
30
import static org .hamcrest .Matchers .is ;
35
- import static org .hibernate .testing .orm .junit .DialectContext .getDialect ;
36
31
37
32
/**
38
- * This test class is about testing that legacy schema that use BLO for JSON column
39
- * can be safely read even when Oracle Oson extention is in place.
33
+ * This test class is about testing that legacy schema that use BLOB or CLOB for JSON columns
34
+ * can be safely read even when Oracle Oson extension is in place.
40
35
* In Such a situation, the JSON type will expect JSON a JSON column and should
41
36
* silently fall back to String deserialization.
42
37
*
@@ -53,11 +48,13 @@ public OracleOsonAsUtf8CompatibilityTest() {
53
48
super ( "JSON" );
54
49
}
55
50
}
51
+
56
52
public static class OracleBlobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
57
53
public OracleBlobAsOsonCompatibilityTest () {
58
54
super ( "BLOB" );
59
55
}
60
56
}
57
+
61
58
public static class OracleClobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
62
59
public OracleClobAsOsonCompatibilityTest () {
63
60
super ( "CLOB" );
@@ -76,14 +73,14 @@ public void setup(SessionFactoryScope scope) {
76
73
scope .inTransaction (
77
74
(session ) -> {
78
75
// force creation of a column type by creating the table ourselves
79
- session .createNativeQuery ( session .getDialect ().getDropTableString ( "TEST_OSON_COMPAT" ) )
76
+ session .createNativeMutationQuery ( session .getDialect ().getDropTableString ( "TEST_OSON_COMPAT" ) )
80
77
.executeUpdate ();
81
78
StringBuilder create = new StringBuilder ();
82
79
create .append ("CREATE TABLE TEST_OSON_COMPAT (" );
83
80
create .append ( "id NUMBER" ).append (',' );
84
- create .append ( "payload " ).append (jsonType ).append (" CHECK (payload is null or json)" ). append ( ',' );
81
+ create .append ( "payload " ).append (jsonType ).append (',' );
85
82
create .append ( "primary key (id))" );
86
- session .createNativeQuery (create .toString ()).executeUpdate ();
83
+ session .createNativeMutationQuery (create .toString ()).executeUpdate ();
87
84
88
85
String insert = "INSERT INTO TEST_OSON_COMPAT (id, payload) VALUES(:id,:json)" ;
89
86
@@ -102,30 +99,22 @@ public void setup(SessionFactoryScope scope) {
102
99
j .append ( "\" theLocalTime\" :\" " ).append (theLocalTime ).append ("\" " );
103
100
j .append ( "}" );
104
101
105
- session .createNativeQuery (insert )
106
- .setParameter ("id" ,1 )
107
- .setParameter ( "json" , j .toString ())
102
+ final Object json = jsonType .equals ( "BLOB" ) ? j .toString ().getBytes () : j .toString ();
103
+ session .createNativeMutationQuery ( insert )
104
+ .setParameter ( "id" , 1 )
105
+ .setParameter ( "json" , json )
108
106
.executeUpdate ();
109
107
}
110
108
);
111
109
}
112
110
113
- @ AfterEach
114
- public void tearDown (SessionFactoryScope scope ) {
115
- scope .inTransaction (
116
- (session ) -> {
117
- session .createNativeQuery ( getDialect ().getDropTableString ( "TEST_OSON_COMPAT" ) ).executeUpdate ();
118
- }
119
- );
120
- }
121
-
122
111
@ Test
123
112
public void verifyReadWorks (SessionFactoryScope scope ) {
124
113
scope .inTransaction (
125
114
(session ) -> {
126
115
JsonEntity entity = session .find ( OracleOsonCompatibilityTest .JsonEntity .class , 1 );
127
- assertThat ( entity .payload .jsonString . getString () , is ( "john" ) );
128
- assertThat ( entity .payload .theUuid , is ( "53886a8a-7082-4879-b430-25cb94415be8" ) );
116
+ assertThat ( entity .payload .jsonString , is ( "john" ) );
117
+ assertThat ( entity .payload .theUuid . toString () , is ( "53886a8a-7082-4879-b430-25cb94415be8" ) );
129
118
}
130
119
);
131
120
}
@@ -139,14 +128,6 @@ public static class JsonEntity {
139
128
@ JdbcTypeCode ( SqlTypes .JSON )
140
129
private JsonEntityPayload payload ;
141
130
142
- public JsonEntity () {
143
- }
144
-
145
- public JsonEntity (Integer id , JsonEntityPayload payload ) {
146
- this .id = id ;
147
- this .payload = payload ;
148
- }
149
-
150
131
public Integer getId () {
151
132
return id ;
152
133
}
@@ -162,26 +143,14 @@ public JsonEntityPayload getPayload() {
162
143
public void setPayload (JsonEntityPayload payload ) {
163
144
this .payload = payload ;
164
145
}
165
-
166
146
}
147
+
167
148
@ Embeddable
168
- @ Access ( AccessType .PROPERTY )
169
149
public static class JsonEntityPayload {
170
- private JsonMappingTests . StringNode jsonString ;
150
+ private String jsonString ;
171
151
private UUID theUuid ;
172
152
private LocalDateTime theLocalDateTime ;
173
153
private LocalDate theLocalDate ;
174
154
private LocalTime theLocalTime ;
175
-
176
- public JsonEntityPayload () {
177
-
178
- }
179
- public JsonEntityPayload (JsonMappingTests .StringNode jsonString , UUID theUuid , LocalDateTime theLocalDateTime , LocalDate theLocalDate , LocalTime theLocalTime ) {
180
- this .jsonString = jsonString ;
181
- this .theUuid = theUuid ;
182
- this .theLocalDateTime = theLocalDateTime ;
183
- this .theLocalDate = theLocalDate ;
184
- this .theLocalTime = theLocalTime ;
185
- }
186
155
}
187
156
}
0 commit comments