Skip to content

Commit 3ff42d8

Browse files
committed
[#2738] Test column type validation in Oracle
1 parent 370f65a commit 3ff42d8

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTestBase.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
package org.hibernate.reactive.schema;
77

88

9+
import java.net.URL;
10+
911
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
12+
import org.hibernate.cfg.AvailableSettings;
1013
import org.hibernate.cfg.Configuration;
1114
import org.hibernate.reactive.BaseReactiveTest;
12-
import org.hibernate.reactive.provider.Settings;
1315
import org.hibernate.reactive.annotations.DisabledFor;
16+
import org.hibernate.reactive.annotations.EnabledFor;
17+
import org.hibernate.reactive.provider.Settings;
1418
import org.hibernate.tool.schema.spi.SchemaManagementException;
1519

1620
import org.junit.jupiter.api.AfterEach;
@@ -19,13 +23,15 @@
1923

2024
import io.vertx.junit5.Timeout;
2125
import io.vertx.junit5.VertxTestContext;
26+
import jakarta.persistence.Column;
2227
import jakarta.persistence.Entity;
2328
import jakarta.persistence.GeneratedValue;
2429
import jakarta.persistence.Id;
2530
import jakarta.persistence.Table;
2631

2732
import static java.util.concurrent.TimeUnit.MINUTES;
2833
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
34+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
2935
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
3036
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;
3137
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -74,6 +80,11 @@ public void before(VertxTestContext context) {
7480
Configuration createConf = constructConfiguration( "create" );
7581
createConf.addAnnotatedClass( BasicTypesTestEntity.class );
7682

83+
final URL importFileURL = Thread.currentThread()
84+
.getContextClassLoader()
85+
.getResource( "oracle-SchemaValidationTest.sql" );
86+
createConf.setProperty( AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE, importFileURL.getFile() );
87+
7788
// Make sure that the extra table is not in the db
7889
Configuration dropConf = constructConfiguration( "drop" );
7990
dropConf.addAnnotatedClass( Extra.class );
@@ -92,6 +103,18 @@ public void after(VertxTestContext context) {
92103
closeFactory( context );
93104
}
94105

106+
@Test
107+
@Timeout(value = 10, timeUnit = MINUTES)
108+
@EnabledFor( ORACLE )
109+
public void testOracleColumnTypeValidation(VertxTestContext context) {
110+
Configuration validateConf = constructConfiguration( "validate" );
111+
validateConf.addAnnotatedClass( Fruit.class );
112+
113+
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
114+
.applySettings( validateConf.getProperties() );
115+
test( context, setupSessionFactory( validateConf ) );
116+
}
117+
95118
// When we have created the table, the validation should pass
96119
@Test
97120
@Timeout(value = 10, timeUnit = MINUTES)
@@ -139,4 +162,43 @@ public static class Extra {
139162

140163
private String description;
141164
}
165+
166+
@Entity(name = "Fruit")
167+
public static class Fruit {
168+
169+
@Id
170+
@GeneratedValue
171+
private Integer id;
172+
173+
@Column(name = "something_name", nullable = false, updatable = false)
174+
private String name;
175+
176+
public Fruit() {
177+
}
178+
179+
public Fruit(String name) {
180+
this.name = name;
181+
}
182+
183+
public Integer getId() {
184+
return id;
185+
}
186+
187+
public void setId(Integer id) {
188+
this.id = id;
189+
}
190+
191+
public String getName() {
192+
return name;
193+
}
194+
195+
public void setName(String name) {
196+
this.name = name;
197+
}
198+
199+
@Override
200+
public String toString() {
201+
return "Fruit{" + id + "," + name + '}';
202+
}
203+
}
142204
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Import file for testing schema validation in SchemaValidationTest
2+
drop table if exists Fruit cascade constraints
3+
drop sequence if exists Fruit_SEQ
4+
5+
-- Create the table manually, so that we can check if the validation succeeds
6+
create sequence fruit_seq start with 1 increment by 50;
7+
create table Fruit (id number(10,0) not null, something_name nvarchar2(20) not null, primary key (id))
8+
9+
INSERT INTO fruit(id, something_name) VALUES (1, 'Cherry');
10+
INSERT INTO fruit(id, something_name) VALUES (2, 'Apple');
11+
INSERT INTO fruit(id, something_name) VALUES (3, 'Banana');
12+
ALTER SEQUENCE fruit_seq RESTART start with 4;

0 commit comments

Comments
 (0)