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 ca981673b4b86406d6d6d2afb0ade97692a51585
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Wed Feb 4 20:49:32 2026 -0600

    GrailsHibernatePersistentProperty
---
 .../orm/hibernate/cfg/GrailsDomainBinder.java      | 31 ++------------
 .../cfg/GrailsHibernatePersistentProperty.java     | 13 ++++--
 .../GrailsHibernatePersistentPropertySpec.groovy   | 48 +++++++++++++++++++++-
 3 files changed, 61 insertions(+), 31 deletions(-)

diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
index 0bec0328de..3eb64cb3da 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
@@ -23,7 +23,6 @@ import org.grails.datastore.mapping.model.PersistentProperty;
 import org.grails.datastore.mapping.model.config.GormProperties;
 import org.grails.datastore.mapping.model.types.Association;
 import org.grails.datastore.mapping.model.types.Basic;
-import org.grails.datastore.mapping.model.types.Embedded;
 import org.grails.datastore.mapping.model.types.ManyToMany;
 import org.grails.datastore.mapping.model.types.TenantId;
 import org.grails.datastore.mapping.model.types.ToMany;
@@ -64,7 +63,6 @@ import org.hibernate.mapping.JoinedSubclass;
 import org.hibernate.mapping.KeyValue;
 import org.hibernate.mapping.ManyToOne;
 import org.hibernate.mapping.OneToMany;
-import org.hibernate.mapping.OneToOne;
 import org.hibernate.mapping.PersistentClass;
 import org.hibernate.mapping.Property;
 import org.hibernate.mapping.RootClass;
@@ -79,7 +77,6 @@ import org.hibernate.metamodel.mapping.JdbcMapping;
 import org.hibernate.service.ServiceRegistry;
 import org.hibernate.type.StandardBasicTypes;
 import org.hibernate.type.Type;
-import org.hibernate.usertype.UserCollectionType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.StringUtils;
@@ -259,7 +256,7 @@ public class GrailsDomainBinder
 
         SimpleValue value = new BasicValue(metadataBuildingContext, 
map.getCollectionTable());
 
-        String type = getIndexColumnType(property, STRING_TYPE);
+        String type = ((GrailsHibernatePersistentProperty) 
property).getIndexColumnType("string");
         String columnName1 = getIndexColumnName(property, 
sessionFactoryBeanName);
         new SimpleValueColumnBinder().bindSimpleValue(value, type, 
columnName1, true);
         PropertyConfig mappedForm = property instanceof 
GrailsHibernatePersistentProperty ghpp ? ghpp.getMappedForm() : new 
PropertyConfig();
@@ -336,8 +333,9 @@ public class GrailsDomainBinder
 
         Table collectionTable = list.getCollectionTable();
         SimpleValue iv = new BasicValue(metadataBuildingContext, 
collectionTable);
-        new SimpleValueColumnBinder().bindSimpleValue(iv, "integer", 
columnName, true);
-        iv.setTypeName("integer");
+        String type = ((GrailsHibernatePersistentProperty) 
property).getIndexColumnType("integer");
+        new SimpleValueColumnBinder().bindSimpleValue(iv, type, columnName, 
true);
+        iv.setTypeName(type);
         list.setIndex(iv);
         list.setBaseIndex(0);
         list.setInverse(false);
@@ -1537,27 +1535,6 @@ public class GrailsDomainBinder
         return getNamingStrategy().resolveColumnName(property.getName()) + 
UNDERSCORE + IndexedCollection.DEFAULT_INDEX_COLUMN_NAME;
     }
 
-    private String getIndexColumnType(@Nonnull PersistentProperty property, 
String defaultType) {
-
-        PropertyConfig pc = property instanceof 
GrailsHibernatePersistentProperty ghpp ? ghpp.getMappedForm() : new 
PropertyConfig();
-
-            if (pc.getIndexColumn() != null && pc.getIndexColumn().getType() 
!= null) {
-
-                Mapping mapping = null;
-                if (property.getOwner() instanceof 
GrailsHibernatePersistentEntity domainClass) {
-                    mapping = domainClass.getMappedForm();
-                }
-
-                if (property instanceof GrailsHibernatePersistentProperty 
ghpp) {
-                    return ghpp.getTypeName(pc.getIndexColumn(), mapping);
-                }
-
-            }
-
-            return defaultType;
-
-        }
-
     private String getMapElementName(PersistentProperty property, String 
sessionFactoryBeanName) {
         PropertyConfig pc = property instanceof 
GrailsHibernatePersistentProperty ghpp ? ghpp.getMappedForm() : new 
PropertyConfig();
 
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java
index 6ecf3787a2..9686ddfffd 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java
@@ -18,9 +18,7 @@ public interface GrailsHibernatePersistentProperty extends 
PersistentProperty<Pr
      * @return The type name
      */
     default String getTypeName() {
-        GrailsHibernatePersistentEntity owner = getHibernateOwner();
-        Mapping mapping = owner != null ? owner.getMappedForm() : null;
-        return getTypeName(getMappedForm(), mapping);
+        return getTypeName(getMappedForm(), 
getHibernateOwner().getMappedForm());
     }
 
     /**
@@ -108,4 +106,13 @@ public interface GrailsHibernatePersistentProperty extends 
PersistentProperty<Pr
         Mapping ownerMapping = getHibernateOwner().getMappedForm();
         return !getHibernateOwner().isRoot() && (ownerMapping == null || 
ownerMapping.getTablePerHierarchy());
     }
+
+
+
+    default String getIndexColumnType(String defaultType) {
+        return Optional.ofNullable(getMappedForm())
+                .map(PropertyConfig::getIndexColumn)
+                .map(ic -> getTypeName(ic, 
getHibernateOwner().getMappedForm()))
+                .orElse(defaultType);
+    }
 }
\ No newline at end of file
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentPropertySpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentPropertySpec.groovy
index aa7c60b8cd..c6dd181adf 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentPropertySpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentPropertySpec.groovy
@@ -76,6 +76,23 @@ class GrailsHibernatePersistentPropertySpec extends 
HibernateGormDatastoreSpec {
         expect:
         property.getTypeName() == "string"
     }
+
+    void "test getIndexColumnType()"() {
+        given:
+        createPersistentEntity(MapValue)
+        PersistentEntity entityWithDefaultMap = 
createPersistentEntity(EntityWithMap)
+        PersistentEntity entityWithCustomMap = 
createPersistentEntity(EntityWithCustomMapIndex)
+        PersistentEntity entityWithList = 
createPersistentEntity(EntityWithList)
+
+        GrailsHibernatePersistentProperty defaultMapProp = 
(GrailsHibernatePersistentProperty) 
entityWithDefaultMap.getPropertyByName("tags")
+        GrailsHibernatePersistentProperty customMapProp = 
(GrailsHibernatePersistentProperty) 
entityWithCustomMap.getPropertyByName("tags")
+        GrailsHibernatePersistentProperty listProp = 
(GrailsHibernatePersistentProperty) entityWithList.getPropertyByName("items")
+
+        expect:
+        defaultMapProp.getIndexColumnType("string") == "string"
+        customMapProp.getIndexColumnType("long") == "long"
+        listProp.getIndexColumnType("integer") == "integer"
+    }
 }
 
 
@@ -149,9 +166,38 @@ class TestEntityWithEmbedded {
 
 
 @Entity
-
 class Address {
 
     String city
 
 }
+
+@Entity
+class EntityWithMap {
+    Long id
+    Map<String, MapValue> tags
+    static hasMany = [tags: MapValue]
+}
+
+@Entity
+class MapValue {
+    Long id
+    String name
+}
+
+@Entity
+class EntityWithCustomMapIndex {
+    Long id
+    Map<Long, MapValue> tags
+    static hasMany = [tags: MapValue]
+    static mapping = {
+        tags indexColumn: [type: 'long']
+    }
+}
+
+@Entity
+class EntityWithList {
+    Long id
+    List<String> items
+    static hasMany = [items: String]
+}

Reply via email to