From e15c9db29f9fb9f6467c05164c6de927cbe87d96 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 31 Dec 2024 16:31:00 +0100 Subject: [PATCH] remove deprecated and very obsolete EnumType --- .../org/hibernate/orm/test}/EnumType.java | 15 +- .../custom_types/FirstLetterType.java | 3 +- .../custom_types/LastNumberType.java | 3 +- ...rNotAvailableDuringTypeResolutionTest.java | 2 +- .../type/typedef/NamedEnumUserType.java | 2 +- .../mapping/converted/enums/Person.hbm.xml | 6 +- .../mapping/converted/enums/mappings.hbm.xml | 4 +- .../orm/test/quote/DataPoint.hbm.xml | 2 +- .../query/hhh12076/Settlement.hbm.xml | 2 +- .../metadata/BasicMetadataGenerator.java | 36 +- .../test/integration/customtype/EnumType.java | 333 ++++++++++++++++++ .../customtype/ExtendedEnumTypeTest.java | 26 +- .../mappings/customType/mappings.hbm.xml | 4 +- .../graalvm/internal/StaticClassLists.java | 3 - .../internal/StaticClassListsTest.java | 1 - 15 files changed, 369 insertions(+), 73 deletions(-) rename hibernate-core/src/{main/java/org/hibernate/type => test/java/org/hibernate/orm/test}/EnumType.java (96%) create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumType.java diff --git a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/EnumType.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/type/EnumType.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/EnumType.java index 3a3995b4bc..04035c037d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/EnumType.java @@ -2,7 +2,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later * Copyright Red Hat Inc. and Hibernate Authors */ -package org.hibernate.type; +package org.hibernate.orm.test; import java.io.Serializable; import java.lang.annotation.Annotation; @@ -18,8 +18,8 @@ import org.hibernate.HibernateException; import org.hibernate.annotations.Nationalized; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.internal.CoreLogging; import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.EnumJavaType; import org.hibernate.type.descriptor.java.JavaType; @@ -31,8 +31,6 @@ import org.hibernate.usertype.DynamicParameterizedType; import org.hibernate.usertype.EnhancedUserType; import org.hibernate.usertype.LoggableUserType; -import org.jboss.logging.Logger; - import static jakarta.persistence.EnumType.ORDINAL; import static jakarta.persistence.EnumType.STRING; import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; @@ -49,7 +47,6 @@ import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; @Deprecated(since="6.2", forRemoval=true) public class EnumType> implements EnhancedUserType, DynamicParameterizedType, LoggableUserType, TypeConfigurationAware, Serializable { - private static final Logger LOG = CoreLogging.logger( EnumType.class ); public static final String ENUM = "enumClass"; public static final String NAMED = "useNamed"; @@ -156,14 +153,6 @@ public class EnumType> jdbcType = descriptor.getRecommendedJdbcType( indicators ); isOrdinal = indicators.getEnumeratedType() != STRING; } - - if ( LOG.isDebugEnabled() ) { - LOG.debugf( - "Using %s-based conversion for Enum %s", - isOrdinal() ? "ORDINAL" : "NAMED", - enumClass.getName() - ); - } } private jakarta.persistence.EnumType getEnumType(ParameterType reader) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java index 9d41084503..bf646e1c66 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java @@ -9,13 +9,14 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import org.hibernate.orm.test.EnumType; import org.hibernate.orm.test.annotations.enumerated.enums.FirstLetter; import org.hibernate.type.descriptor.WrapperOptions; /** * @author Janario Oliveira */ -public class FirstLetterType extends org.hibernate.type.EnumType { +public class FirstLetterType extends EnumType { @Override public int getSqlType() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java index b0c9b3d068..370fc1023f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java @@ -9,13 +9,14 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import org.hibernate.orm.test.EnumType; import org.hibernate.orm.test.annotations.enumerated.enums.LastNumber; import org.hibernate.type.descriptor.WrapperOptions; /** * @author Janario Oliveira */ -public class LastNumberType extends org.hibernate.type.EnumType { +public class LastNumberType extends EnumType { @Override public int getSqlType() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringTypeResolutionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringTypeResolutionTest.java index 5f3a61b4f3..804b932bba 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringTypeResolutionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringTypeResolutionTest.java @@ -64,7 +64,7 @@ public class ExtendedBeanManagerNotAvailableDuringTypeResolutionTest { " \n" + " \n" + " \n" + - " \n" + + " \n" + " " + MyEnum.class.getName() + "\n" + " \n" + " \n" + diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/typedef/NamedEnumUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/typedef/NamedEnumUserType.java index 9bf88aaef0..0caef67ae0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/typedef/NamedEnumUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/typedef/NamedEnumUserType.java @@ -6,7 +6,7 @@ package org.hibernate.orm.test.mapping.type.typedef; import java.util.Properties; -import org.hibernate.type.EnumType; +import org.hibernate.orm.test.EnumType; /** * A simple user type where we force enums to be saved by name, not ordinal diff --git a/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/Person.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/Person.hbm.xml index 846f11f992..0a020c86b8 100644 --- a/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/Person.hbm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/Person.hbm.xml @@ -16,20 +16,20 @@ - + org.hibernate.orm.test.mapping.converted.enums.Gender 12 - + org.hibernate.orm.test.mapping.converted.enums.HairColor - + org.hibernate.orm.test.mapping.converted.enums.HairColor 12 diff --git a/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/mappings.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/mappings.hbm.xml index 8342032d8a..54c7917f1a 100644 --- a/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/mappings.hbm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/mappings.hbm.xml @@ -12,13 +12,13 @@ - + org.hibernate.orm.test.mapping.converted.enums.UnspecifiedEnumTypeEntity$E1 - + org.hibernate.orm.test.mapping.converted.enums.UnspecifiedEnumTypeEntity$E2 diff --git a/hibernate-core/src/test/resources/org/hibernate/orm/test/quote/DataPoint.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/quote/DataPoint.hbm.xml index 3ef22085a9..c9b0bdabae 100644 --- a/hibernate-core/src/test/resources/org/hibernate/orm/test/quote/DataPoint.hbm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/orm/test/quote/DataPoint.hbm.xml @@ -11,7 +11,7 @@ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" > - + org.hibernate.orm.test.quote.DataPoint$DataPointEnum diff --git a/hibernate-core/src/test/resources/org/hibernate/query/hhh12076/Settlement.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/query/hhh12076/Settlement.hbm.xml index d1a677c363..5e81de5a59 100644 --- a/hibernate-core/src/test/resources/org/hibernate/query/hhh12076/Settlement.hbm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/query/hhh12076/Settlement.hbm.xml @@ -36,7 +36,7 @@ - + 12 org.hibernate.orm.test.query.hhh12076.SettlementStatus diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java index 4300facf77..e9327004d6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java @@ -14,8 +14,6 @@ import org.hibernate.envers.internal.entities.mapper.SimpleMapperBuilder; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Value; import org.hibernate.type.BasicType; -import org.hibernate.type.CustomType; -import org.hibernate.type.EnumType; import org.hibernate.type.Type; /** @@ -58,21 +56,6 @@ public final class BasicMetadataGenerator { return false; } - private void mapEnumerationType(TypeSpecification typeDefinition, EnumType type, Properties parameters) { - if ( parameters.getProperty( EnumType.ENUM ) != null ) { - typeDefinition.setParameter( EnumType.ENUM, parameters.getProperty( EnumType.ENUM ) ); - } - else { - typeDefinition.setParameter( EnumType.ENUM, type.getEnumClass().getName() ); - } - if ( parameters.getProperty( EnumType.NAMED ) != null ) { - typeDefinition.setParameter( EnumType.NAMED, parameters.getProperty( EnumType.NAMED ) ); - } - else { - typeDefinition.setParameter( EnumType.NAMED, Boolean.toString( !type.isOrdinal() ) ); - } - } - private boolean isAddNestedType(Value value) { if ( value instanceof SimpleValue simpleValue ) { return simpleValue.getTypeParameters() != null; @@ -99,19 +82,12 @@ public final class BasicMetadataGenerator { final TypeSpecification typeSpecification = new TypeSpecification( typeName ); attribute.setType( typeSpecification ); - Type type = value.getType(); - if ( type instanceof CustomType && ((CustomType) type).getUserType() instanceof EnumType ) { - // Proper handling of nasty legacy EnumType - mapEnumerationType( typeSpecification, (EnumType) ((CustomType) type).getUserType(), typeParameters ); - } - else { - // By default, copying all Hibernate properties - for ( Object object : typeParameters.keySet() ) { - final String keyType = (String) object; - final String property = typeParameters.getProperty( keyType ); - if ( property != null ) { - typeSpecification.setParameter( keyType, property ); - } + // By default, copying all Hibernate properties + for ( Object object : typeParameters.keySet() ) { + final String keyType = (String) object; + final String property = typeParameters.getProperty( keyType ); + if ( property != null ) { + typeSpecification.setParameter( keyType, property ); } } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumType.java new file mode 100644 index 0000000000..e377337e42 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/EnumType.java @@ -0,0 +1,333 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.envers.test.integration.customtype; + +import jakarta.persistence.Enumerated; +import jakarta.persistence.MapKeyEnumerated; +import org.hibernate.AssertionFailure; +import org.hibernate.HibernateException; +import org.hibernate.annotations.Nationalized; +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.type.SqlTypes; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.java.EnumJavaType; +import org.hibernate.type.descriptor.java.JavaType; +import org.hibernate.type.descriptor.jdbc.JdbcType; +import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; +import org.hibernate.type.spi.TypeConfiguration; +import org.hibernate.type.spi.TypeConfigurationAware; +import org.hibernate.usertype.DynamicParameterizedType; +import org.hibernate.usertype.EnhancedUserType; +import org.hibernate.usertype.LoggableUserType; + +import java.io.Serializable; +import java.lang.annotation.Annotation; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; + +import static jakarta.persistence.EnumType.ORDINAL; +import static jakarta.persistence.EnumType.STRING; +import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; + +/** + * Value type mapper for enumerations. + * + * @author Emmanuel Bernard + * @author Hardy Ferentschik + * @author Steve Ebersole + * + * @deprecated Use the built-in support for enums + */ +@Deprecated(since="6.2", forRemoval=true) +public class EnumType> + implements EnhancedUserType, DynamicParameterizedType, LoggableUserType, TypeConfigurationAware, Serializable { + + public static final String ENUM = "enumClass"; + public static final String NAMED = "useNamed"; + public static final String TYPE = "type"; + + private Class enumClass; + + private boolean isOrdinal; + private JdbcType jdbcType; + private EnumJavaType enumJavaType; + + private TypeConfiguration typeConfiguration; + + public EnumType() { + } + + public Class getEnumClass() { + return enumClass; + } + + @Override + public JdbcType getJdbcType(TypeConfiguration typeConfiguration) { + return jdbcType; + } + + /** + *

+ * An instance of this class is "configured" by a call to {@link #setParameterValues}, + * where configuration parameters are given as entries in a {@link Properties} object. + * There are two distinct ways an instance may be configured: + *

    + *
  • one for {@code hbm.xml}-based mapping, and + *
  • another for annotation-based or {@code orm.xml}-based mapping. + *
+ *

+ * In the case of annotations or {@code orm.xml}, a {@link ParameterType} is passed to + * {@link #setParameterValues} under the key {@value #PARAMETER_TYPE}. + *

+ * But in the case of {@code hbm.xml}, there are multiple parameters: + *

    + *
  • + * {@value #ENUM}, the name of the Java enumeration class. + *
  • + *
  • + * {@value #NAMED}, specifies if the enum should be mapped by name. + * Default is to map as ordinal. + *
  • + *
  • + * {@value #TYPE}, a JDBC type code (legacy alternative to {@value #NAMED}). + *
  • + *
+ */ + @Override + public void setParameterValues(Properties parameters) { + // IMPL NOTE: we handle 2 distinct cases here: + // 1) we are passed a ParameterType instance in the incoming Properties - generally + // speaking this indicates the annotation-binding case, and the passed ParameterType + // represents information about the attribute and annotation + // 2) we are not passed a ParameterType - generally this indicates a hbm.xml binding case. + final ParameterType reader = (ParameterType) parameters.get( PARAMETER_TYPE ); + + if ( parameters.containsKey( ENUM ) ) { + final String enumClassName = (String) parameters.get( ENUM ); + try { + enumClass = (Class) ReflectHelper.classForName( enumClassName, this.getClass() ).asSubclass( Enum.class ); + } + catch ( ClassNotFoundException exception ) { + throw new HibernateException("Enum class not found: " + enumClassName, exception); + } + } + else if ( reader != null ) { + enumClass = (Class) reader.getReturnedClass().asSubclass( Enum.class ); + } + + final JavaType descriptor = typeConfiguration.getJavaTypeRegistry().getDescriptor( enumClass ); + enumJavaType = (EnumJavaType) descriptor; + + if ( parameters.containsKey( TYPE ) ) { + int jdbcTypeCode = Integer.parseInt( (String) parameters.get( TYPE ) ); + jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( jdbcTypeCode ); + isOrdinal = jdbcType.isInteger() + // Both, ENUM and NAMED_ENUM are treated like ordinal with respect to the ordering + || jdbcType.getDefaultSqlTypeCode() == SqlTypes.ENUM + || jdbcType.getDefaultSqlTypeCode() == SqlTypes.NAMED_ENUM; + } + else { + final LocalJdbcTypeIndicators indicators; + final Long columnLength = reader == null ? null : reader.getColumnLengths()[0]; + if ( parameters.containsKey(NAMED) ) { + indicators = new LocalJdbcTypeIndicators( + // use ORDINAL as default for hbm.xml mappings + getBoolean( NAMED, parameters ) ? STRING : ORDINAL, + false, + columnLength + ); + } + else { + indicators = new LocalJdbcTypeIndicators( + getEnumType( reader ), + isNationalized( reader ), + columnLength + ); + } + jdbcType = descriptor.getRecommendedJdbcType( indicators ); + isOrdinal = indicators.getEnumeratedType() != STRING; + } + } + + private jakarta.persistence.EnumType getEnumType(ParameterType reader) { + if ( reader != null ) { + if ( reader.isPrimaryKey() ) { + final MapKeyEnumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), MapKeyEnumerated.class ); + if ( enumAnn != null ) { + return enumAnn.value(); + } + } + final Enumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), Enumerated.class ); + if ( enumAnn != null ) { + return enumAnn.value(); + } + } + return ORDINAL; + } + + private boolean isNationalized(ParameterType reader) { + return typeConfiguration.getCurrentBaseSqlTypeIndicators().isNationalized() + || reader!=null && getAnnotation( reader.getAnnotationsMethod(), Nationalized.class ) != null; + } + + @SuppressWarnings("unchecked") + private A getAnnotation(Annotation[] annotations, Class annotationType) { + for ( Annotation annotation : annotations ) { + if ( annotationType.isInstance( annotation ) ) { + return (A) annotation; + } + } + return null; + } + + @Override + public int getSqlType() { + verifyConfigured(); + return jdbcType.getJdbcTypeCode(); + } + + @Override + public Class returnedClass() { + return enumClass; + } + + @Override + public boolean equals(T x, T y) throws HibernateException { + return x == y; + } + + @Override + public int hashCode(T x) throws HibernateException { + return x == null ? 0 : x.hashCode(); + } + + @Override + public T nullSafeGet(ResultSet rs, int position, WrapperOptions options) + throws SQLException { + verifyConfigured(); + return jdbcType.getExtractor( enumJavaType ).extract( rs, position, options ); + } + + private void verifyConfigured() { + if ( enumJavaType == null ) { + throw new AssertionFailure("EnumType (" + enumClass.getName() + ") not properly, fully configured"); + } + } + + @Override + public void nullSafeSet(PreparedStatement st, T value, int index, WrapperOptions options) + throws SQLException { + verifyConfigured(); + jdbcType.getBinder( enumJavaType ).bind( st, value, index, options ); + } + + @Override + public T deepCopy(T value) throws HibernateException { + return value; + } + + @Override + public boolean isMutable() { + return false; + } + + @Override + public Serializable disassemble(T value) throws HibernateException { + return value; + } + + @Override + public T assemble(Serializable cached, Object owner) throws HibernateException { + return (T) cached; + } + + @Override + public T replace(T original, T target, Object owner) throws HibernateException { + return original; + } + + @Override + public TypeConfiguration getTypeConfiguration() { + return typeConfiguration; + } + + @Override + public void setTypeConfiguration(TypeConfiguration typeConfiguration) { + this.typeConfiguration = typeConfiguration; + } + + @Override + public String toSqlLiteral(T value) { + verifyConfigured(); + return isOrdinal() + ? Integer.toString( value.ordinal() ) + : "'" + value.name() + "'"; + } + + @Override + public String toString(T value) { + verifyConfigured(); + return enumJavaType.toName( value ); + } + + @Override + public T fromStringValue(CharSequence sequence) { + verifyConfigured(); + return enumJavaType.fromName( sequence.toString() ); + } + + @Override @SuppressWarnings("unchecked") + public String toLoggableString(Object value, SessionFactoryImplementor factory) { + verifyConfigured(); + return enumJavaType.extractLoggableRepresentation( (T) value ); + } + + public boolean isOrdinal() { + verifyConfigured(); + return isOrdinal; + } + + private class LocalJdbcTypeIndicators implements JdbcTypeIndicators { + private final jakarta.persistence.EnumType enumType; + private final boolean nationalized; + private final Long columnLength; + + private LocalJdbcTypeIndicators(jakarta.persistence.EnumType enumType, boolean nationalized, Long columnLength) { + this.enumType = enumType; + this.nationalized = nationalized; + this.columnLength = columnLength; + } + + @Override + public TypeConfiguration getTypeConfiguration() { + return typeConfiguration; + } + + @Override + public jakarta.persistence.EnumType getEnumeratedType() { + return enumType != null ? enumType : typeConfiguration.getCurrentBaseSqlTypeIndicators().getEnumeratedType(); + } + + @Override + public boolean isNationalized() { + return nationalized; + } + + + @Override + public long getColumnLength() { + return columnLength == null ? NO_COLUMN_LENGTH : columnLength; + } + + @Override + public Dialect getDialect() { + return typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect(); + } + } +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ExtendedEnumTypeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ExtendedEnumTypeTest.java index 53ae6c0be2..2437343d34 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ExtendedEnumTypeTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ExtendedEnumTypeTest.java @@ -31,11 +31,10 @@ import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; /** - * Tests that a custom type which extends {@link org.hibernate.type.EnumType} continues to be - * recognized as an EnumType rather than a basic custom type implementation since the values + * Tests that a custom type which extends {@link org.hibernate.envers.test.integration.customtype.EnumType} + * continues to be recognized as an EnumType rather than a basic custom type implementation since the values * which envers sends to describe the type in HBM differ whether its an Enum or not. * * Without the fix, this test would not even bootstrap and would throw a MappingException. @@ -47,7 +46,7 @@ public class ExtendedEnumTypeTest extends BaseEnversJPAFunctionalTestCase { // An extended type to trigger the need for Envers to supply type information in the HBM mappings. // This should be treated the same as any other property annotated as Enumerated or uses an Enum. - public static class ExtendedEnumType extends org.hibernate.type.EnumType { + public static class ExtendedEnumType extends org.hibernate.envers.test.integration.customtype.EnumType { } @@ -176,16 +175,17 @@ public class ExtendedEnumTypeTest extends BaseEnversJPAFunctionalTestCase { final UserType userType = ( (CustomType) propertyType ).getUserType(); assertTyping( typeClass, userType ); - assertTyping( org.hibernate.type.EnumType.class, userType ); + assertTyping( org.hibernate.envers.test.integration.customtype.EnumType.class, userType ); - switch ( expectedType ) { - case STRING: - assertTrue( !( (org.hibernate.type.EnumType) userType ).isOrdinal() ); - break; - default: - assertTrue( ( (org.hibernate.type.EnumType) userType ).isOrdinal() ); - break; - } + // org,hibernate.type.EnumType used to be special-cased in the Envers code +// switch ( expectedType ) { +// case STRING: +// assertTrue( !( (org.hibernate.envers.test.integration.customtype.EnumType) userType ).isOrdinal() ); +// break; +// default: +// assertTrue( ( (org.hibernate.envers.test.integration.customtype.EnumType) userType ).isOrdinal() ); +// break; +// } } ); } } diff --git a/hibernate-envers/src/test/resources/mappings/customType/mappings.hbm.xml b/hibernate-envers/src/test/resources/mappings/customType/mappings.hbm.xml index abc0224eeb..cf2b05b047 100644 --- a/hibernate-envers/src/test/resources/mappings/customType/mappings.hbm.xml +++ b/hibernate-envers/src/test/resources/mappings/customType/mappings.hbm.xml @@ -12,14 +12,14 @@ - + org.hibernate.orm.test.envers.entities.customtype.UnspecifiedEnumTypeEntity$E1 - + org.hibernate.orm.test.envers.entities.customtype.UnspecifiedEnumTypeEntity$E2 diff --git a/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java b/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java index 66e6be18ab..ab59caae37 100644 --- a/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java +++ b/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java @@ -6,7 +6,6 @@ package org.hibernate.graalvm.internal; import org.hibernate.tool.schema.internal.script.MultiLineSqlScriptExtractor; -import org.hibernate.type.EnumType; /** * The place to list all "static" types we know of that need to be possible to @@ -36,9 +35,7 @@ final class StaticClassLists { org.hibernate.id.enhanced.SequenceStyleGenerator.class, org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl.class, org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl.class, - EnumType.class, MultiLineSqlScriptExtractor.class, - }; } diff --git a/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java b/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java index 056e88d507..cd95e366de 100644 --- a/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java +++ b/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java @@ -114,7 +114,6 @@ public class StaticClassListsTest { org.hibernate.id.enhanced.SequenceStyleGenerator.class, org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl.class, org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl.class, - org.hibernate.type.EnumType.class, org.hibernate.tool.schema.internal.script.MultiLineSqlScriptExtractor.class ); }