diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 06f46baff1..d515f2c7d4 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -30,6 +30,7 @@ import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableStrate import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.sql.ast.spi.ParameterMarkerStrategy; +import org.hibernate.type.WrapperArrayHandling; import jakarta.persistence.criteria.CriteriaDelete; import jakarta.persistence.criteria.CriteriaQuery; @@ -2768,6 +2769,19 @@ public interface AvailableSettings { @Incubating String XML_FORMAT_MAPPER = "hibernate.type.xml_format_mapper"; + /** + * Configurable control over how to handle {@code Byte[]} and {@code Character[]} types + * encountered in the application domain model. Allowable semantics are defined by + * {@link WrapperArrayHandling}. Accepted values include:
    + *
  1. {@link WrapperArrayHandling} instance
  2. + *
  3. case-insensitive name of a {@link WrapperArrayHandling} instance (e.g. {@code allow})
  4. + *
+ * + * @since 6.2 + */ + @Incubating + String WRAPPER_ARRAY_HANDLING = "hibernate.type.wrapper_array_handling"; + /** * Specifies the default strategy for storage of the timezone information for the zoned * datetime types {@link java.time.OffsetDateTime} and {@link java.time.ZonedDateTime}. diff --git a/hibernate-core/src/main/java/org/hibernate/type/WrapperArrayHandling.java b/hibernate-core/src/main/java/org/hibernate/type/WrapperArrayHandling.java new file mode 100644 index 0000000000..53fa4c6e72 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/type/WrapperArrayHandling.java @@ -0,0 +1,46 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.type; + +import org.hibernate.type.descriptor.java.ByteArrayJavaType; +import org.hibernate.type.descriptor.java.CharacterArrayJavaType; + +/** + * Possible options for how to handle {@code Byte[]} and {@code Character[]} basic mappings + * encountered in the application domain model. + * + * @author Steve Ebersole + * + * @since 6.2 + */ +public enum WrapperArrayHandling { + /** + * Throw an informative and actionable error if the types are used explicitly in the domain model + * + * @implNote The default behavior + */ + DISALLOW, + + /** + * Allows the use of the wrapper arrays. Stores the arrays using {@linkplain SqlTypes#ARRAY ARRAY} + * or {@linkplain SqlTypes#SQLXML SQLXML} SQL types to maintain proper null element semantics. + */ + ALLOW, + + /** + * Allows the use of the wrapper arrays. Stores the arrays using {@linkplain SqlTypes#VARBINARY VARBINARY} + * and {@linkplain SqlTypes#VARCHAR VARCHAR}, disallowing null elements. + * + * @see ByteArrayJavaType + * @see CharacterArrayJavaType + * + * @implNote The pre-6.2 behavior + * @apiNote Hibernate recommends users who want the legacy semantic change the domain model to use + * {@code byte[]} and {@code char[]} rather than using this setting. + */ + LEGACY +}