88import jakarta .persistence .Id ;
99import jakarta .persistence .Table ;
1010import org .hibernate .annotations .JdbcTypeCode ;
11+ import org .hibernate .cfg .DialectSpecificSettings ;
1112import org .hibernate .dialect .OracleDialect ;
1213import org .hibernate .orm .test .mapping .basic .JsonMappingTests ;
1314import org .hibernate .testing .orm .junit .DomainModel ;
1415import org .hibernate .testing .orm .junit .RequiresDialect ;
16+ import org .hibernate .testing .orm .junit .ServiceRegistry ;
1517import org .hibernate .testing .orm .junit .SessionFactory ;
1618import org .hibernate .testing .orm .junit .SessionFactoryScope ;
19+ import org .hibernate .testing .orm .junit .Setting ;
1720import org .hibernate .type .SqlTypes ;
1821import org .junit .jupiter .api .AfterEach ;
1922import org .junit .jupiter .api .BeforeEach ;
2023import org .junit .jupiter .api .Test ;
2124
22-
2325import static org .hamcrest .MatcherAssert .assertThat ;
2426import static org .hamcrest .Matchers .is ;
2527import static org .hibernate .testing .orm .junit .DialectContext .getDialect ;
3234 *
3335 * @author Emmanuel Jannetti
3436 */
35- @ DomainModel (annotatedClasses = JsonCBLOBToOsonTest .JsonEntity .class )
36- @ SessionFactory
37+ @ DomainModel (annotatedClasses = OracleOsonCompatibilityTest .JsonEntity .class )
38+ @ SessionFactory ( exportSchema = false )
3739@ 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 {
4741
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" );
5046 }
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" );
5451 }
5552 }
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+ }
5665
5766 @ BeforeEach
5867 public void setup (SessionFactoryScope scope ) {
5968 scope .inTransaction (
6069 (session ) -> {
6170 // 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" ) )
6372 .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))" )
6574 .executeUpdate ();
6675
6776 String insert = "INSERT INTO TEST_OSON_COMPAT (id, jsonName) VALUES(:id,:json)" ;
@@ -85,11 +94,26 @@ public void tearDown(SessionFactoryScope scope) {
8594 public void verifyReadWorks (SessionFactoryScope scope ) {
8695 scope .inTransaction (
8796 (session ) -> {
88- JsonEntity entity = session .find ( JsonCBLOBToOsonTest .JsonEntity .class , 1 );
97+ JsonEntity entity = session .find ( OracleOsonCompatibilityTest .JsonEntity .class , 1 );
8998 assertThat ( entity .jsonName .getString (), is ( "john" ) );
90-
9199 }
92100 );
93101 }
94102
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+ }
95119}
0 commit comments