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 e42e555be86b5d635c1c1970f3ee033164dc99ac
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Wed Feb 4 17:01:48 2026 -0600

    Fix GrailsDomainBinder in 5
---
 .../orm/hibernate/cfg/GrailsDomainBinder.java      | 105 ++++++++++++++++++++-
 .../orm/hibernate/cfg/GrailsDomainBinder.java      |   1 -
 .../GrailsHibernatePersistentPropertySpec.groovy   |   3 +-
 .../domainbinding/GrailsPropertyBinderSpec.groovy  |  16 ++--
 4 files changed, 112 insertions(+), 13 deletions(-)

diff --git 
a/grails-data-hibernate5/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
 
b/grails-data-hibernate5/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
index 500f405ca4..1c5715728c 100644
--- 
a/grails-data-hibernate5/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
+++ 
b/grails-data-hibernate5/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
@@ -119,7 +119,6 @@ import org.grails.datastore.mapping.model.types.ToOne;
 import org.grails.datastore.mapping.reflect.EntityReflector;
 import org.grails.datastore.mapping.reflect.NameUtils;
 import org.grails.orm.hibernate.access.TraitPropertyAccessStrategy;
-import 
org.grails.orm.hibernate.cfg.domainbinding.collectionType.CollectionType;
 
 /**
  * Handles the binding Grails domain classes and properties to the Hibernate 
runtime meta model.
@@ -158,7 +157,6 @@ public class GrailsDomainBinder implements 
MetadataContributor {
     }
 
     protected final CollectionType CT = new CollectionType(null, this) {
-        @Override
         public Collection create(ToMany property, PersistentClass owner, 
String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) 
{
             return null;
         }
@@ -3501,6 +3499,109 @@ public class GrailsDomainBinder implements 
MetadataContributor {
         }
     }
 
+    /**
+     * A Collection type, for the moment only Set is supported
+     *
+     * @author Graeme
+     */
+    static abstract class CollectionType {
+
+        protected final Class<?> clazz;
+        protected final GrailsDomainBinder binder;
+        protected final MetadataBuildingContext buildingContext;
+
+        protected CollectionType SET;
+        protected CollectionType LIST;
+        protected CollectionType BAG;
+        protected CollectionType MAP;
+        protected boolean initialized;
+
+        protected final Map<Class<?>, CollectionType> INSTANCES = new 
HashMap<>();
+
+        public abstract Collection create(ToMany property, PersistentClass 
owner,
+                                          String path, 
InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws 
MappingException;
+
+        protected CollectionType(Class<?> clazz, GrailsDomainBinder binder) {
+            this.clazz = clazz;
+            this.binder = binder;
+            this.buildingContext = binder.getMetadataBuildingContext();
+        }
+
+        @Override
+        public String toString() {
+            return clazz.getName();
+        }
+
+        protected void createInstances() {
+
+            if (initialized) {
+                return;
+            }
+
+            initialized = true;
+
+            SET = new CollectionType(Set.class, binder) {
+                @Override
+                public Collection create(ToMany property, PersistentClass 
owner,
+                                         String path, 
InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws 
MappingException {
+                    org.hibernate.mapping.Set coll = new 
org.hibernate.mapping.Set(buildingContext, owner);
+                    coll.setCollectionTable(owner.getTable());
+                    coll.setTypeName(getTypeName(property));
+                    binder.bindCollection(property, coll, owner, mappings, 
path, sessionFactoryBeanName);
+                    return coll;
+                }
+            };
+            INSTANCES.put(Set.class, SET);
+            INSTANCES.put(SortedSet.class, SET);
+
+            LIST = new CollectionType(List.class, binder) {
+                @Override
+                public Collection create(ToMany property, PersistentClass 
owner,
+                                         String path, 
InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws 
MappingException {
+                    org.hibernate.mapping.List coll = new 
org.hibernate.mapping.List(buildingContext, owner);
+                    coll.setCollectionTable(owner.getTable());
+                    coll.setTypeName(getTypeName(property));
+                    binder.bindCollection(property, coll, owner, mappings, 
path, sessionFactoryBeanName);
+                    return coll;
+                }
+            };
+            INSTANCES.put(List.class, LIST);
+
+            BAG = new CollectionType(java.util.Collection.class, binder) {
+                @Override
+                public Collection create(ToMany property, PersistentClass 
owner,
+                                         String path, 
InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws 
MappingException {
+                    Bag coll = new Bag(buildingContext, owner);
+                    coll.setCollectionTable(owner.getTable());
+                    coll.setTypeName(getTypeName(property));
+                    binder.bindCollection(property, coll, owner, mappings, 
path, sessionFactoryBeanName);
+                    return coll;
+                }
+            };
+            INSTANCES.put(java.util.Collection.class, BAG);
+
+            MAP = new CollectionType(Map.class, binder) {
+                @Override
+                public Collection create(ToMany property, PersistentClass 
owner,
+                                         String path, 
InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws 
MappingException {
+                    org.hibernate.mapping.Map map = new 
org.hibernate.mapping.Map(buildingContext, owner);
+                    map.setTypeName(getTypeName(property));
+                    binder.bindCollection(property, map, owner, mappings, 
path, sessionFactoryBeanName);
+                    return map;
+                }
+            };
+            INSTANCES.put(Map.class, MAP);
+        }
+
+        public CollectionType collectionTypeForClass(Class<?> clazz) {
+            createInstances();
+            return INSTANCES.get(clazz);
+        }
+
+        public String getTypeName(ToMany property) {
+            return binder.getTypeName(property, 
binder.getPropertyConfig(property), getMapping(property.getOwner()));
+        }
+
     }
 
 }
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 571026902e..0bec0328de 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
@@ -315,7 +315,6 @@ public class GrailsDomainBinder
     }
 
     /**
-     * @TODO NOT TESTED
      * @param property
      * @param mappings
      * @param persistentClasses
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 3b7ce0fd1c..aa7c60b8cd 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
@@ -68,8 +68,6 @@ class GrailsHibernatePersistentPropertySpec extends 
HibernateGormDatastoreSpec {
         property.isEmbedded()
     }
 
-
-
     void "test getTypeName()"() {
         given:
         PersistentEntity entity = 
createPersistentEntity(TestEntityWithTypeName)
@@ -80,6 +78,7 @@ class GrailsHibernatePersistentPropertySpec extends 
HibernateGormDatastoreSpec {
     }
 }
 
+
 enum TestEnum {
     A, B
 }
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 4fa0d1f806..b8fddef382 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
@@ -13,14 +13,14 @@ import org.hibernate.mapping.SimpleValue
 
 class GrailsPropertyBinderSpec extends HibernateGormDatastoreSpec {
 
-//    void setupSpec() {
-//        manager.addAllDomainClasses([
-//            org.apache.grails.data.testing.tck.domains.Pet,
-//            org.apache.grails.data.testing.tck.domains.Person,
-//            org.apache.grails.data.testing.tck.domains.PetType,
-//            org.apache.grails.data.testing.tck.domains.PersonWithCompositeKey
-//        ])
-//    }
+    void setupSpec() {
+        manager.addAllDomainClasses([
+            org.apache.grails.data.testing.tck.domains.Pet,
+            org.apache.grails.data.testing.tck.domains.Person,
+            org.apache.grails.data.testing.tck.domains.PetType,
+            org.apache.grails.data.testing.tck.domains.PersonWithCompositeKey
+        ])
+    }
 
     void "Test bind simple property"() {
         given:

Reply via email to