diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/DB2Database.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/DB2Database.java index d40e073059..aed78164af 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/DB2Database.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/DB2Database.java @@ -73,6 +73,11 @@ class DB2Database implements TestableDatabase { expectedDBTypeForClass.put( Character.class, "CHARACTER" ); expectedDBTypeForClass.put( char.class, "CHARACTER" ); expectedDBTypeForClass.put( String.class, "VARCHAR" ); + expectedDBTypeForClass.put( String[].class, "VARBINARY" ); + expectedDBTypeForClass.put( Long[].class, "VARBINARY" ); + expectedDBTypeForClass.put( BigDecimal[].class, "VARBINARY" ); + expectedDBTypeForClass.put( BigInteger[].class, "VARBINARY" ); + expectedDBTypeForClass.put( Boolean[].class, "VARBINARY" ); }} /** diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MSSQLServerDatabase.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MSSQLServerDatabase.java index a1d1a6767c..8078d1b7e7 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MSSQLServerDatabase.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MSSQLServerDatabase.java @@ -82,6 +82,11 @@ class MSSQLServerDatabase implements TestableDatabase { expectedDBTypeForClass.put( Character.class, "char" ); expectedDBTypeForClass.put( char.class, "char" ); expectedDBTypeForClass.put( String.class, "varchar" ); + expectedDBTypeForClass.put( String[].class, "varbinary" ); + expectedDBTypeForClass.put( Long[].class, "varbinary" ); + expectedDBTypeForClass.put( BigDecimal[].class, "varbinary" ); + expectedDBTypeForClass.put( BigInteger[].class, "varbinary" ); + expectedDBTypeForClass.put( Boolean[].class, "varbinary" ); }} /** diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MySQLDatabase.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MySQLDatabase.java index a8b3f0ed44..b0050cde81 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MySQLDatabase.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MySQLDatabase.java @@ -73,6 +73,11 @@ class MySQLDatabase implements TestableDatabase { expectedDBTypeForClass.put( Character.class, "char" ); expectedDBTypeForClass.put( char.class, "char" ); expectedDBTypeForClass.put( String.class, "varchar" ); + expectedDBTypeForClass.put( String[].class, "varbinary" ); + expectedDBTypeForClass.put( Long[].class, "varbinary" ); + expectedDBTypeForClass.put( BigDecimal[].class, "varbinary" ); + expectedDBTypeForClass.put( BigInteger[].class, "varbinary" ); + expectedDBTypeForClass.put( Boolean[].class, "varbinary" ); }}; /** diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/OracleDatabase.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/OracleDatabase.java index d3f8a950a8..e27b157885 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/OracleDatabase.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/OracleDatabase.java @@ -81,6 +81,12 @@ class OracleDatabase implements TestableDatabase { expectedDBTypeForClass.put( Character.class, "CHAR" ); expectedDBTypeForClass.put( char.class, "CHAR" ); expectedDBTypeForClass.put( String.class, "VARCHAR2" ); + expectedDBTypeForClass.put( String[].class, "STRINGARRAY" ); + expectedDBTypeForClass.put( Long[].class, "LONGARRAY" ); + expectedDBTypeForClass.put( BigDecimal[].class, "BIGDECIMALARRAY" ); + expectedDBTypeForClass.put( BigInteger[].class, "BIGINTEGERARRAY" ); + expectedDBTypeForClass.put( Boolean[].class, "BOOLEANARRAY" ); + } } diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/PostgreSQLDatabase.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/PostgreSQLDatabase.java index b44163b77e..592c288b5a 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/PostgreSQLDatabase.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/PostgreSQLDatabase.java @@ -73,6 +73,11 @@ class PostgreSQLDatabase implements TestableDatabase { expectedDBTypeForClass.put( Character.class, "character" ); expectedDBTypeForClass.put( char.class, "character" ); expectedDBTypeForClass.put( String.class, "character varying" ); + expectedDBTypeForClass.put( String[].class, "ARRAY" ); + expectedDBTypeForClass.put( Long[].class, "ARRAY" ); + expectedDBTypeForClass.put( BigDecimal[].class, "ARRAY" ); + expectedDBTypeForClass.put( BigInteger[].class, "ARRAY" ); + expectedDBTypeForClass.put( Boolean[].class, "ARRAY" ); }} /** diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/BasicTypesTestEntity.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/BasicTypesTestEntity.java index 75567438dc..5daadaf193 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/BasicTypesTestEntity.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/BasicTypesTestEntity.java @@ -18,6 +18,9 @@ import java.util.Date; import java.util.TimeZone; import java.util.UUID; + +import org.hibernate.annotations.Array; + import jakarta.persistence.Column; import jakarta.persistence.Convert; import jakarta.persistence.Entity; @@ -102,6 +105,31 @@ public class BasicTypesTestEntity { Duration duration; + String[] stringArray; + + @Array( length = 5 ) + String[] stringArrayAnnotated; + + Long[] longArray; + + @Array( length = 5 ) + Long[] longArrayAnnotated; + + BigDecimal[] bigDecimalArray; + + @Array( length = 5 ) + BigDecimal[] bigDecimalArrayAnnotated; + + BigInteger[] bigIntegerArray; + + @Array( length = 5 ) + BigInteger[] bigIntegerArrayAnnotated; + + Boolean[] fieldBooleanArray; + + @Array( length = 5 ) + Boolean[] fieldBooleanArrayAnnotated; + Serializable serializable; public BasicTypesTestEntity() { diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/ColumnTypesMappingTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/ColumnTypesMappingTest.java index c57621608f..02af0ea3fc 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/ColumnTypesMappingTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/ColumnTypesMappingTest.java @@ -215,4 +215,54 @@ public void testLocalDateTimeType(VertxTestContext context) { public void testSerializableType(VertxTestContext context) { testDatatype( context, "serializable", Serializable.class ); } + + @Test + public void testStringArrayType(VertxTestContext context) { + testDatatype( context, "stringArray", String[].class ); + } + + @Test + public void testStringArrayAnnotatedType(VertxTestContext context) { + testDatatype( context, "stringArrayAnnotated", String[].class ); + } + + @Test + public void testLongArrayType(VertxTestContext context) { + testDatatype( context, "longArray", Long[].class ); + } + + @Test + public void testLongArrayAnnotatedType(VertxTestContext context) { + testDatatype( context, "longArrayAnnotated", Long[].class ); + } + + @Test + public void testBigDecimalArrayType(VertxTestContext context) { + testDatatype( context, "bigDecimalArray", BigDecimal[].class ); + } + + @Test + public void testBigDecimalArrayAnnotatedType(VertxTestContext context) { + testDatatype( context, "bigDecimalArrayAnnotated", BigDecimal[].class ); + } + + @Test + public void testBigIntegerArrayType(VertxTestContext context) { + testDatatype( context, "bigIntegerArray", BigInteger[].class ); + } + + @Test + public void testBigIntegerArrayAnnotatedType(VertxTestContext context) { + testDatatype( context, "bigIntegerArrayAnnotated", BigInteger[].class ); + } + + @Test + public void testFieldBooleanArrayType(VertxTestContext context) { + testDatatype( context, "fieldBooleanArray", Boolean[].class ); + } + + @Test + public void testFieldBooleanArrayAnnotatedType(VertxTestContext context) { + testDatatype( context, "fieldBooleanArrayAnnotated", Boolean[].class ); + } } diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTestBase.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTestBase.java index 15f9c7e373..2c1803e9c9 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTestBase.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTestBase.java @@ -9,6 +9,7 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.reactive.BaseReactiveTest; +import org.hibernate.reactive.annotations.DisabledForDbTypes; import org.hibernate.reactive.provider.Settings; import org.hibernate.reactive.annotations.DisabledFor; import org.hibernate.tool.schema.spi.SchemaManagementException; @@ -25,7 +26,9 @@ import jakarta.persistence.Table; import static java.util.concurrent.TimeUnit.MINUTES; +import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.COCKROACHDB; import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2; +import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL; import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED; import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -38,7 +41,17 @@ * - TODO: Missing column * - TODO: Wrong column type */ -@DisabledFor(value = DB2, reason = "No InformationExtractor for Dialect [org.hibernate.dialect.DB2Dialect..]") +@DisabledForDbTypes({ + @DisabledFor(value = DB2, reason = "No InformationExtractor for Dialect [org.hibernate.dialect.DB2Dialect..]"), + @DisabledFor(value = COCKROACHDB, + reason = " " + + "but was: "), + @DisabledFor(value = POSTGRESQL, + reason = " " + + "but was: ") +}) public abstract class SchemaValidationTestBase extends BaseReactiveTest { public static class IndividuallyStrategyTest extends SchemaValidationTestBase { diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JavaTypesArrayTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JavaTypesArrayTest.java index a9b08ac0d6..8838c64b5f 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JavaTypesArrayTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JavaTypesArrayTest.java @@ -17,6 +17,7 @@ import java.util.UUID; import java.util.function.Consumer; +import org.hibernate.annotations.Array; import org.hibernate.reactive.BaseReactiveTest; import org.hibernate.reactive.annotations.DisabledFor; @@ -277,36 +278,68 @@ public void testBigDecimalArrayType(VertxTestContext context) { } ); } + @Test + public void testArrayWithLengthAnnotationNotChecked(VertxTestContext context) { + Basic basic = new Basic(); + // String[] array has a length set to 10 via @Array(length = 10) annotation + // Construct an array larger than 10. + // When a length check is provided via ORM or Reactive, this test should fail. + String[] dataArray = {"s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s10", "s11" }; + basic.stringArray = dataArray; + + testField( context, basic, found -> assertArrayEquals( dataArray, found.stringArray ) ); + } + @Entity(name = "Basic") @Table(name = "Basic") private static class Basic { @Id @GeneratedValue Integer id; + @Array( length = 10 ) String[] stringArray; + @Array( length = 10 ) Boolean[] booleanArray; + @Array( length = 10 ) boolean[] primitiveBooleanArray; + @Array( length = 10 ) Integer[] integerArray; + @Array( length = 10 ) int[] primitiveIntegerArray; + @Array( length = 10 ) Long[] longArray; + @Array( length = 10 ) long[] primitiveLongArray; + @Array( length = 10 ) Float[] floatArray; + @Array( length = 10 ) float[] primitiveFloatArray; + @Array( length = 10 ) Double[] doubleArray; + @Array( length = 10 ) double[] primitiveDoubleArray; + @Array( length = 10 ) UUID[] uuidArray; + @Array( length = 10 ) AnEnum[] enumArray; + @Array( length = 10 ) Short[] shortArray; + @Array( length = 10 ) short[] primitiveShortArray; + @Array( length = 10 ) Date[] dateArray; + @Array( length = 10 ) LocalDate[] localDateArray; + @Array( length = 10 ) LocalTime[] localTimeArray; + @Array( length = 10 ) LocalDateTime[] localDateTimeArray; - + @Array( length = 10 ) // We have to specify the length for BigDecimal and BigInteger because // the default column type when creating the schema is too small on some databases @Column(length = 5000) BigInteger[] bigIntegerArray; + @Array( length = 10 ) @Column(length = 5000) BigDecimal[] bigDecimalArray; }