8
8
import jakarta .persistence .Id ;
9
9
import jakarta .persistence .Table ;
10
10
import org .hibernate .annotations .JdbcTypeCode ;
11
+ import org .hibernate .cfg .DialectSpecificSettings ;
11
12
import org .hibernate .dialect .OracleDialect ;
12
13
import org .hibernate .orm .test .mapping .basic .JsonMappingTests ;
13
14
import org .hibernate .testing .orm .junit .DomainModel ;
14
15
import org .hibernate .testing .orm .junit .RequiresDialect ;
16
+ import org .hibernate .testing .orm .junit .ServiceRegistry ;
15
17
import org .hibernate .testing .orm .junit .SessionFactory ;
16
18
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
19
+ import org .hibernate .testing .orm .junit .Setting ;
17
20
import org .hibernate .type .SqlTypes ;
18
21
import org .junit .jupiter .api .AfterEach ;
19
22
import org .junit .jupiter .api .BeforeEach ;
20
23
import org .junit .jupiter .api .Test ;
21
24
22
-
23
25
import static org .hamcrest .MatcherAssert .assertThat ;
24
26
import static org .hamcrest .Matchers .is ;
25
27
import static org .hibernate .testing .orm .junit .DialectContext .getDialect ;
32
34
*
33
35
* @author Emmanuel Jannetti
34
36
*/
35
- @ DomainModel (annotatedClasses = JsonCBLOBToOsonTest .JsonEntity .class )
36
- @ SessionFactory
37
+ @ DomainModel (annotatedClasses = OracleOsonCompatibilityTest .JsonEntity .class )
38
+ @ SessionFactory ( exportSchema = false )
37
39
@ RequiresDialect ( value = OracleDialect .class , majorVersion = 23 )
38
- public class JsonCBLOBToOsonTest {
39
-
40
- @ Entity (name = "JsonEntity" )
41
- @ Table (name = "TEST_OSON_COMPAT" )
42
- public static class JsonEntity {
43
- @ Id
44
- private Integer id ;
45
- @ JdbcTypeCode ( SqlTypes .JSON )
46
- private JsonMappingTests .StringNode jsonName ;
40
+ public abstract class OracleOsonCompatibilityTest {
47
41
48
- public JsonEntity () {
49
- super ();
42
+ @ ServiceRegistry (settings = @ Setting (name = DialectSpecificSettings .ORACLE_OSON_DISABLED , value = "true" ))
43
+ public static class OracleOsonAsUtf8CompatibilityTest extends OracleOsonCompatibilityTest {
44
+ public OracleOsonAsUtf8CompatibilityTest () {
45
+ super ( "JSON" );
50
46
}
51
- public JsonEntity (Integer id , JsonMappingTests .StringNode node ) {
52
- this .id = id ;
53
- this .jsonName = node ;
47
+ }
48
+ public static class OracleBlobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
49
+ public OracleBlobAsOsonCompatibilityTest () {
50
+ super ( "BLOB" );
54
51
}
55
52
}
53
+ public static class OracleClobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
54
+ public OracleClobAsOsonCompatibilityTest () {
55
+ super ( "CLOB" );
56
+ }
57
+ }
58
+
59
+
60
+ private final String jsonType ;
61
+
62
+ public OracleOsonCompatibilityTest (String jsonType ) {
63
+ this .jsonType = jsonType ;
64
+ }
56
65
57
66
@ BeforeEach
58
67
public void setup (SessionFactoryScope scope ) {
59
68
scope .inTransaction (
60
69
(session ) -> {
61
70
// force creation of a BLOB column type by creating the table ourselves
62
- session .createNativeQuery ( getDialect ().getDropTableString ( "TEST_OSON_COMPAT" ) )
71
+ session .createNativeQuery ( session . getDialect ().getDropTableString ( "TEST_OSON_COMPAT" ) )
63
72
.executeUpdate ();
64
- session .createNativeQuery ( "CREATE TABLE TEST_OSON_COMPAT (id NUMBER, jsonName BLOB CHECK (jsonName is json) ,primary key (id))" )
73
+ session .createNativeQuery ( "CREATE TABLE TEST_OSON_COMPAT (id NUMBER, jsonName " + jsonType + " CHECK (jsonName is json) ,primary key (id))" )
65
74
.executeUpdate ();
66
75
67
76
String insert = "INSERT INTO TEST_OSON_COMPAT (id, jsonName) VALUES(:id,:json)" ;
@@ -85,11 +94,26 @@ public void tearDown(SessionFactoryScope scope) {
85
94
public void verifyReadWorks (SessionFactoryScope scope ) {
86
95
scope .inTransaction (
87
96
(session ) -> {
88
- JsonEntity entity = session .find ( JsonCBLOBToOsonTest .JsonEntity .class , 1 );
97
+ JsonEntity entity = session .find ( OracleOsonCompatibilityTest .JsonEntity .class , 1 );
89
98
assertThat ( entity .jsonName .getString (), is ( "john" ) );
90
-
91
99
}
92
100
);
93
101
}
94
102
103
+ @ Entity (name = "JsonEntity" )
104
+ @ Table (name = "TEST_OSON_COMPAT" )
105
+ public static class JsonEntity {
106
+ @ Id
107
+ private Integer id ;
108
+ @ JdbcTypeCode ( SqlTypes .JSON )
109
+ private JsonMappingTests .StringNode jsonName ;
110
+
111
+ public JsonEntity () {
112
+ super ();
113
+ }
114
+ public JsonEntity (Integer id , JsonMappingTests .StringNode node ) {
115
+ this .id = id ;
116
+ this .jsonName = node ;
117
+ }
118
+ }
95
119
}
0 commit comments