This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 0c11ddd604035b73eb0a8af891c6318ad4d1be0a
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Sun Feb 22 21:33:00 2026 -0600

    Removed need for HibernateLegacyEnumType
---
 grails-data-hibernate7/DEPRECATIONS.md             |   7 -
 grails-data-hibernate7/{core => }/build-full.csv   |   3 -
 .../orm/hibernate/HibernateLegacyEnumType.java     | 347 ---------------------
 .../cfg/domainbinding/binder/EnumTypeBinder.java   |  34 +-
 .../domainbinding/binder/GrailsDomainBinder.java   |   3 +-
 .../secondpass/CollectionWithJoinTableBinder.java  |   2 +-
 .../cfg/domainbinding/util/GrailsEnumType.java     |  17 +-
 .../cfg/domainbinding/EnumTypeBinderSpec.groovy    |  26 +-
 .../domainbinding/GrailsPropertyBinderSpec.groovy  |   7 +-
 9 files changed, 49 insertions(+), 397 deletions(-)

diff --git a/grails-data-hibernate7/DEPRECATIONS.md 
b/grails-data-hibernate7/DEPRECATIONS.md
index 42a4ebc346..de23915818 100644
--- a/grails-data-hibernate7/DEPRECATIONS.md
+++ b/grails-data-hibernate7/DEPRECATIONS.md
@@ -17,13 +17,6 @@ Generated from a clean build of `grails-data-hibernate7` 
(and its four Gradle su
 
 | Fully Qualified Class Name | Line | Warning |
 |---|---|---|
-| `org.grails.orm.hibernate.HibernateLegacyEnumType` | 61 | `[serial]` 
serializable class HibernateLegacyEnumType has no definition of 
serialVersionUID |
-| `org.grails.orm.hibernate.HibernateLegacyEnumType` | 63 | `[removal]` 
DynamicParameterizedType in org.hibernate.usertype has been deprecated and 
marked for removal |
-| `org.grails.orm.hibernate.HibernateLegacyEnumType` | 123 | `[unchecked]` 
unchecked cast |
-| `org.grails.orm.hibernate.HibernateLegacyEnumType` | 128 | `[unchecked]` 
unchecked cast |
-| `org.grails.orm.hibernate.HibernateLegacyEnumType` | 221 | `[removal]` 
nullSafeGet(ResultSet,int,SharedSessionContractImplementor,Object) in UserType 
has been deprecated and marked for removal |
-| `org.grails.orm.hibernate.HibernateLegacyEnumType` | 236 | `[removal]` 
nullSafeSet(PreparedStatement,J,int,SharedSessionContractImplementor) in 
UserType has been deprecated and marked for removal |
-| `org.grails.orm.hibernate.HibernateLegacyEnumType` | 260 | `[unchecked]` 
unchecked cast |
 | `org.grails.orm.hibernate.access.TraitPropertyAccessStrategy` | 39 | 
`[rawtypes]` found raw type: Class |
 | `org.grails.orm.hibernate.access.TraitPropertyAccessStrategy` | 117 | 
`[rawtypes]` found raw type: Class |
 | `org.grails.orm.hibernate.cfg.HibernateMappingContext` | 39 | `[rawtypes]` 
found raw type: Class |
diff --git a/grails-data-hibernate7/core/build-full.csv 
b/grails-data-hibernate7/build-full.csv
similarity index 99%
rename from grails-data-hibernate7/core/build-full.csv
rename to grails-data-hibernate7/build-full.csv
index f9740ff2a6..932c165c11 100644
--- a/grails-data-hibernate7/core/build-full.csv
+++ b/grails-data-hibernate7/build-full.csv
@@ -97,9 +97,6 @@ 
org.grails.orm.hibernate.HibernateDatastore,742,CloseResource,Ensure that resour
 org.grails.orm.hibernate.HibernateDatastore,754,DataflowAnomalyAnalysis,Found 
'DD'-anomaly for variable 'metadata' (lines '754'-'763').
 org.grails.orm.hibernate.HibernateDatastore,755,CloseResource,Ensure that 
resources like this ServiceRegistry object are closed after use
 org.grails.orm.hibernate.HibernateDatastore,763,DataflowAnomalyAnalysis,Found 
'DD'-anomaly for variable 'metadata' (lines '763'-'763').
-org.grails.orm.hibernate.HibernateLegacyEnumType,61,MissingSerialVersionUID,Classes
 implementing Serializable should set a serialVersionUID
-org.grails.orm.hibernate.HibernateLegacyEnumType,75,AvoidFieldNameMatchingMethodName,Field
 isOrdinal has the same name as a method
-org.grails.orm.hibernate.HibernateLegacyEnumType,116,DataflowAnomalyAnalysis,Found
 'DU'-anomaly for variable 'reader' (lines '116'-'163').
 
org.grails.orm.hibernate.HibernateMappingContextSessionFactoryBean,460,UseProperClassLoader,"In
 J2EE, getClassLoader() might not work as expected.  Use 
Thread.currentThread().getContextClassLoader() instead."
 
org.grails.orm.hibernate.HibernateMappingContextSessionFactoryBean,502,EmptyIfStmt,Avoid
 empty if statements
 org.grails.orm.hibernate.HibernateSession,80,DataflowAnomalyAnalysis,Found 
'DU'-anomaly for variable 'cpf' (lines '80'-'88').
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateLegacyEnumType.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateLegacyEnumType.java
deleted file mode 100644
index 10dddd90f9..0000000000
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateLegacyEnumType.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    https://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.grails.orm.hibernate;
-
-import static jakarta.persistence.EnumType.ORDINAL;
-import static jakarta.persistence.EnumType.STRING;
-import static 
org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
-
-import jakarta.persistence.EnumType;
-import jakarta.persistence.Enumerated;
-import jakarta.persistence.MapKeyEnumerated;
-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 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.engine.spi.SharedSessionContractImplementor;
-import org.hibernate.internal.util.ReflectHelper;
-import org.hibernate.type.SqlTypes;
-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 org.jboss.logging.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Value type mapper for enumerations.
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- * @author Steve Ebersole
- */
-public class HibernateLegacyEnumType<T extends Enum<T>>
-    implements EnhancedUserType<T>,
-        DynamicParameterizedType,
-        LoggableUserType,
-        TypeConfigurationAware,
-        Serializable {
-  private static final org.slf4j.Logger LOG = 
LoggerFactory.getLogger(EnumType.class);
-
-  public static final String ENUM = "enumClass";
-  public static final String NAMED = "useNamed";
-  public static final String TYPE = "type";
-
-  private Class<T> enumClass;
-
-  private boolean isOrdinal;
-  private JdbcType jdbcType;
-  private EnumJavaType<T> enumJavaType;
-
-  private TypeConfiguration typeConfiguration;
-
-  public HibernateLegacyEnumType() {}
-
-  public Class<T> getEnumClass() {
-    return enumClass;
-  }
-
-  /**
-   * 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:
-   *
-   * <ul>
-   *   <li>one for {@code hbm.xml}-based mapping, and
-   *   <li>another for annotation-based or {@code orm.xml}-based mapping.
-   * </ul>
-   *
-   * <p>In the case of annotations or {@code orm.xml}, a {@link ParameterType} 
is passed to {@link
-   * #setParameterValues} under the key {@value #PARAMETER_TYPE}.
-   *
-   * <p>But in the case of {@code hbm.xml}, there are multiple parameters:
-   *
-   * <ul>
-   *   <li>{@value #ENUM}, the name of the Java enumeration class.
-   *   <li>{@value #NAMED}, specifies if the enum should be mapped by name. 
Default is to map as
-   *       ordinal.
-   *   <li>{@value #TYPE}, a JDBC type code (legacy alternative to {@value 
#NAMED}).
-   * </ul>
-   */
-  @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<T>)
-                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<T>) reader.getReturnedClass().asSubclass(Enum.class);
-    }
-
-    final JavaType<T> descriptor = 
typeConfiguration.getJavaTypeRegistry().getDescriptor(enumClass);
-    enumJavaType = (EnumJavaType<T>) 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;
-    }
-
-    if (LOG.isDebugEnabled()) {
-      LOG.debug(
-          "Using {}-based conversion for Enum {}",
-          isOrdinal() ? "ORDINAL" : "NAMED", enumClass.getName());
-    }
-  }
-
-  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 extends Annotation> A getAnnotation(
-      Annotation[] annotations, Class<A> 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<T> 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, SharedSessionContractImplementor session, 
Object owner)
-      throws SQLException {
-    verifyConfigured();
-    return jdbcType.getExtractor(enumJavaType).extract(rs, position, session);
-  }
-
-  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, 
SharedSessionContractImplementor session)
-      throws HibernateException, SQLException {
-    verifyConfigured();
-    jdbcType.getBinder(enumJavaType).bind(st, value, index, session);
-  }
-
-  @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/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java
index 3eba126b31..ad6f6ee61d 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java
@@ -19,22 +19,18 @@
 package org.grails.orm.hibernate.cfg.domainbinding.binder;
 
 import static 
org.grails.orm.hibernate.cfg.domainbinding.binder.GrailsDomainBinder.ENUM_CLASS_PROP;
-import static 
org.grails.orm.hibernate.cfg.domainbinding.binder.GrailsDomainBinder.ENUM_TYPE_CLASS;
 
-import java.sql.Types;
 import java.util.Properties;
-import org.grails.orm.hibernate.HibernateLegacyEnumType;
+import jakarta.persistence.EnumType;
 import org.grails.orm.hibernate.cfg.ColumnConfig;
 import org.grails.orm.hibernate.cfg.IdentityEnumType;
 import org.grails.orm.hibernate.cfg.PropertyConfig;
 import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentProperty;
 import 
org.grails.orm.hibernate.cfg.domainbinding.util.ColumnNameForPropertyAndPathFetcher;
 import org.grails.orm.hibernate.cfg.domainbinding.util.GrailsEnumType;
-import org.hibernate.MappingException;
 import org.hibernate.boot.spi.MetadataBuildingContext;
 import org.hibernate.mapping.BasicValue;
 import org.hibernate.mapping.Column;
-import org.hibernate.mapping.SimpleValue;
 import org.hibernate.mapping.Table;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -81,29 +77,27 @@ public class EnumTypeBinder {
   public void bindEnumType(
       GrailsHibernatePersistentProperty property,
       Class<?> propertyType,
-      SimpleValue simpleValue,
+      BasicValue simpleValue,
       String columnName) {
     PropertyConfig pc = property.getMappedForm();
-    String enumType = pc.getEnumType();
     Properties enumProperties = new Properties();
     enumProperties.put(ENUM_CLASS_PROP, propertyType.getName());
     String typeName = property.getTypeName(propertyType);
     if (typeName != null) {
       simpleValue.setTypeName(typeName);
     } else {
-      if (GrailsEnumType.DEFAULT.getType().equals(enumType)
-          || GrailsEnumType.STRING.getType().equalsIgnoreCase(enumType)) {
-        simpleValue.setTypeName(ENUM_TYPE_CLASS);
-        enumProperties.put(HibernateLegacyEnumType.TYPE, 
String.valueOf(Types.VARCHAR));
-        enumProperties.put(HibernateLegacyEnumType.NAMED, 
Boolean.TRUE.toString());
-      } else if (GrailsEnumType.ORDINAL.getType().equalsIgnoreCase(enumType)) {
-        simpleValue.setTypeName(ENUM_TYPE_CLASS);
-        enumProperties.put(HibernateLegacyEnumType.TYPE, 
String.valueOf(Types.INTEGER));
-        enumProperties.put(HibernateLegacyEnumType.NAMED, 
Boolean.FALSE.toString());
-      } else if (GrailsEnumType.IDENTITY.getType().equals(enumType)) {
-        simpleValue.setTypeName(IdentityEnumType.class.getName());
-      } else {
-        throw new MappingException("Invalid enum type [" + enumType + "].");
+      switch (GrailsEnumType.fromString(pc.getEnumType())) {
+        case DEFAULT, STRING -> {
+          // Hibernate 7 native string enum mapping: store by Enum.name() as 
VARCHAR.
+          simpleValue.setImplicitJavaTypeAccess(tc -> propertyType);
+          simpleValue.setEnumerationStyle(EnumType.STRING);
+        }
+        case ORDINAL -> {
+          // Hibernate 7 native ordinal enum mapping: store by Enum.ordinal() 
as INTEGER.
+          simpleValue.setImplicitJavaTypeAccess(tc -> propertyType);
+          simpleValue.setEnumerationStyle(EnumType.ORDINAL);
+        }
+        case IDENTITY -> 
simpleValue.setTypeName(IdentityEnumType.class.getName());
       }
     }
     simpleValue.setTypeParameters(enumProperties);
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java
index 02e7c224c9..b06b402758 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java
@@ -61,8 +61,7 @@ public class GrailsDomainBinder implements 
AdditionalMappingContributor, TypeCon
   public static final String EMPTY_PATH = "";
   public static final char UNDERSCORE = '_';
 
-  public static final String ENUM_TYPE_CLASS =
-      org.grails.orm.hibernate.HibernateLegacyEnumType.class.getName();
+
   public static final String ENUM_CLASS_PROP = "enumClass";
   public static final Logger LOG = 
LoggerFactory.getLogger(GrailsDomainBinder.class);
 
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java
index 9b9890a563..e6b235cc6a 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java
@@ -112,7 +112,7 @@ public class CollectionWithJoinTableBinder {
       }
 
       if (isEnum) {
-        enumTypeBinder.bindEnumType(property, referencedType, element, 
columnName);
+        enumTypeBinder.bindEnumType(property, referencedType, (BasicValue) 
element, columnName);
       } else {
 
         String typeName = property.getTypeName(referencedType);
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/GrailsEnumType.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/GrailsEnumType.java
index 82efcf2aad..01d9a99a29 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/GrailsEnumType.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/GrailsEnumType.java
@@ -18,18 +18,33 @@
  */
 package org.grails.orm.hibernate.cfg.domainbinding.util;
 
+import org.hibernate.MappingException;
+
 public enum GrailsEnumType {
   DEFAULT("default"),
   STRING("string"),
   ORDINAL("ordinal"),
   IDENTITY("identity");
+
   private final String type;
 
-  private GrailsEnumType(String type) {
+  GrailsEnumType(String type) {
     this.type = type;
   }
 
   public String getType() {
     return type;
   }
+
+  public static GrailsEnumType fromString(String value) {
+    if (value == null || DEFAULT.type.equalsIgnoreCase(value)) {
+      return DEFAULT;
+    }
+    for (GrailsEnumType candidate : values()) {
+      if (candidate.type.equalsIgnoreCase(value)) {
+        return candidate;
+      }
+    }
+    throw new MappingException("Invalid enum type [" + value + "]. Valid 
values are: default, string, ordinal, identity.");
+  }
 }
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy
index 7891b5ce78..95e66c9c03 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy
@@ -5,6 +5,8 @@ import grails.persistence.Entity
 import org.grails.datastore.mapping.model.PersistentProperty
 import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentProperty
 import org.grails.orm.hibernate.cfg.IdentityEnumType
+import jakarta.persistence.EnumType
+import org.grails.orm.hibernate.cfg.domainbinding.binder.GrailsDomainBinder
 import org.grails.orm.hibernate.cfg.domainbinding.util.BackticksRemover
 import 
org.grails.orm.hibernate.cfg.domainbinding.util.ColumnNameForPropertyAndPathFetcher
 import org.grails.orm.hibernate.cfg.domainbinding.util.DefaultColumnNameFetcher
@@ -12,7 +14,6 @@ import 
org.hibernate.engine.spi.SharedSessionContractImplementor
 import org.hibernate.mapping.BasicValue
 import org.hibernate.mapping.Column
 import org.hibernate.mapping.Table
-import org.grails.orm.hibernate.HibernateLegacyEnumType
 import org.hibernate.usertype.UserType
 import spock.lang.Subject
 import spock.lang.Unroll
@@ -20,7 +21,6 @@ import spock.lang.Unroll
 import java.sql.PreparedStatement
 import java.sql.ResultSet
 import java.sql.SQLException
-import java.sql.Types
 
 import 
org.grails.orm.hibernate.cfg.domainbinding.binder.ColumnConfigToColumnBinder
 import org.grails.orm.hibernate.cfg.domainbinding.binder.EnumTypeBinder
@@ -62,20 +62,19 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec 
{
 
         then: "the correct hibernate type is set"
         simpleValue.getTypeName() == expectedHibernateType
+        simpleValue.getEnumerationStyle() == expectedEnumStyle
         simpleValue.isNullable() == nullable
 
-        and: "the type parameters are configured correctly"
-        def props = simpleValue.getTypeParameters()
-        (props.getProperty(HibernateLegacyEnumType.TYPE) == 
String.valueOf(expectedSqlType)) == typeExpected
-        (props.getProperty(HibernateLegacyEnumType.NAMED) == 
String.valueOf(namedExpected)) == namedIsExpected
+        and: "the enum class property is always set"
+        
simpleValue.getTypeParameters().getProperty(GrailsDomainBinder.ENUM_CLASS_PROP) 
== Status01.name
 
         where:
-        clazz | enumTypeMapping   | expectedHibernateType            | 
expectedSqlType   | typeExpected | namedExpected | namedIsExpected | nullable
-        Person01| "default"       | HibernateLegacyEnumType.class.getName()    
     | Types.VARCHAR     | true         | true          | true            | 
false
-        Person02|"string"         | HibernateLegacyEnumType.class.getName()    
     | Types.VARCHAR     | true         | true          | true            | true
-        Person03|"ordinal"        | HibernateLegacyEnumType.class.getName()    
     | Types.INTEGER     | true         | false         | true            | true
-        Person04|"identity"       | IdentityEnumType.class.getName() | null    
          | false        | null          | false           | false
-        Person05|UserTypeEnumType | UserTypeEnumType.class.getName() | null    
          | false        | null          | false           | false
+        clazz    | enumTypeMapping  | expectedHibernateType                   
| expectedEnumStyle | nullable
+        Person01 | "default"        | null                                    
| EnumType.STRING   | false
+        Person02 | "string"         | null                                    
| EnumType.STRING   | true
+        Person03 | "ordinal"        | null                                    
| EnumType.ORDINAL  | true
+        Person04 | "identity"       | IdentityEnumType.class.getName()        
| null              | false
+        Person05 | UserTypeEnumType | UserTypeEnumType.class.getName()        
| null              | false
     }
 
 
@@ -148,7 +147,8 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec 
{
         then: "a BasicValue is returned and bound correctly"
         result instanceof BasicValue
         result.getTable() == table
-        result.getTypeName() == HibernateLegacyEnumType.class.getName()
+        result.getTypeName() == null
+        result.getEnumerationStyle() == EnumType.STRING
         result.getColumns().size() == 1
         result.getColumns()[0].getName() == "status"
     }
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy
index 8f1813678f..0301f68639 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy
@@ -262,9 +262,10 @@ class GrailsPropertyBinderSpec extends 
HibernateGormDatastoreSpec {
         then:
         Property prop = rootClass.getProperty("status")
         prop != null
-        prop.value instanceof SimpleValue
-        // Enums use HibernateLegacyEnumType by default in Grails
-        ((SimpleValue)prop.value).typeName == 
GrailsDomainBinder.ENUM_TYPE_CLASS
+        prop.value instanceof BasicValue
+        // Default enum mapping uses Hibernate 7 native STRING style (no 
typeName)
+        ((BasicValue)prop.value).typeName == null
+        ((BasicValue)prop.value).enumerationStyle == 
jakarta.persistence.EnumType.STRING
     }
 
     void "Test bind many-to-one"() {

Reply via email to