Skip to content

Commit d175308

Browse files
mbelladebeikov
authored andcommitted
HHH-17404 Oson compatibility test fixes
1 parent f18fa56 commit d175308

File tree

1 file changed

+15
-46
lines changed

1 file changed

+15
-46
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh17404/OracleOsonCompatibilityTest.java

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@
44
*/
55
package org.hibernate.orm.test.mapping.hhh17404;
66

7-
import jakarta.persistence.Access;
8-
import jakarta.persistence.AccessType;
97
import jakarta.persistence.Embeddable;
108
import jakarta.persistence.Entity;
119
import jakarta.persistence.Id;
1210
import jakarta.persistence.Table;
1311
import org.hibernate.annotations.JdbcTypeCode;
1412
import org.hibernate.cfg.DialectSpecificSettings;
1513
import org.hibernate.dialect.OracleDialect;
16-
import org.hibernate.orm.test.mapping.basic.JsonMappingTests;
1714
import org.hibernate.testing.orm.junit.DomainModel;
1815
import org.hibernate.testing.orm.junit.RequiresDialect;
1916
import org.hibernate.testing.orm.junit.ServiceRegistry;
2017
import org.hibernate.testing.orm.junit.SessionFactory;
2118
import org.hibernate.testing.orm.junit.SessionFactoryScope;
2219
import org.hibernate.testing.orm.junit.Setting;
2320
import org.hibernate.type.SqlTypes;
24-
import org.junit.jupiter.api.AfterEach;
2521
import org.junit.jupiter.api.BeforeEach;
2622
import org.junit.jupiter.api.Test;
2723

@@ -32,11 +28,10 @@
3228

3329
import static org.hamcrest.MatcherAssert.assertThat;
3430
import static org.hamcrest.Matchers.is;
35-
import static org.hibernate.testing.orm.junit.DialectContext.getDialect;
3631

3732
/**
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.
4035
* In Such a situation, the JSON type will expect JSON a JSON column and should
4136
* silently fall back to String deserialization.
4237
*
@@ -53,11 +48,13 @@ public OracleOsonAsUtf8CompatibilityTest() {
5348
super( "JSON" );
5449
}
5550
}
51+
5652
public static class OracleBlobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
5753
public OracleBlobAsOsonCompatibilityTest() {
5854
super( "BLOB" );
5955
}
6056
}
57+
6158
public static class OracleClobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
6259
public OracleClobAsOsonCompatibilityTest() {
6360
super( "CLOB" );
@@ -76,14 +73,14 @@ public void setup(SessionFactoryScope scope) {
7673
scope.inTransaction(
7774
(session) -> {
7875
// 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" ) )
8077
.executeUpdate();
8178
StringBuilder create = new StringBuilder();
8279
create.append("CREATE TABLE TEST_OSON_COMPAT (");
8380
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(',');
8582
create.append( "primary key (id))");
86-
session.createNativeQuery(create.toString()).executeUpdate();
83+
session.createNativeMutationQuery(create.toString()).executeUpdate();
8784

8885
String insert = "INSERT INTO TEST_OSON_COMPAT (id, payload) VALUES(:id,:json)";
8986

@@ -102,30 +99,22 @@ public void setup(SessionFactoryScope scope) {
10299
j.append( "\"theLocalTime\":\"").append(theLocalTime).append("\"" );
103100
j.append( "}" );
104101

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 )
108106
.executeUpdate();
109107
}
110108
);
111109
}
112110

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-
122111
@Test
123112
public void verifyReadWorks(SessionFactoryScope scope) {
124113
scope.inTransaction(
125114
(session) -> {
126115
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" ) );
129118
}
130119
);
131120
}
@@ -139,14 +128,6 @@ public static class JsonEntity {
139128
@JdbcTypeCode( SqlTypes.JSON )
140129
private JsonEntityPayload payload;
141130

142-
public JsonEntity() {
143-
}
144-
145-
public JsonEntity(Integer id, JsonEntityPayload payload) {
146-
this.id = id;
147-
this.payload = payload;
148-
}
149-
150131
public Integer getId() {
151132
return id;
152133
}
@@ -162,26 +143,14 @@ public JsonEntityPayload getPayload() {
162143
public void setPayload(JsonEntityPayload payload) {
163144
this.payload = payload;
164145
}
165-
166146
}
147+
167148
@Embeddable
168-
@Access( AccessType.PROPERTY )
169149
public static class JsonEntityPayload {
170-
private JsonMappingTests.StringNode jsonString;
150+
private String jsonString;
171151
private UUID theUuid;
172152
private LocalDateTime theLocalDateTime;
173153
private LocalDate theLocalDate;
174154
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-
}
186155
}
187156
}

0 commit comments

Comments
 (0)