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

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

commit 2d7d0439988131a9df931a826e4b47d4b25cbb3e
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Sun Mar 15 17:07:17 2026 -0500

    hibernate 7:  remove unnecessary collection arguments
---
 .../cfg/domainbinding/binder/CollectionBinder.java |   6 +-
 .../binder/CollectionForPropertyConfigBinder.java  |   4 +-
 .../cfg/domainbinding/binder/EnumTypeBinder.java   |  12 +-
 .../domainbinding/binder/GrailsPropertyBinder.java |   4 +-
 .../secondpass/BasicCollectionElementBinder.java   |   3 +-
 .../secondpass/BidirectionalMapElementBinder.java  |   5 +-
 .../secondpass/CollectionKeyBinder.java            |   3 +-
 .../secondpass/CollectionKeyColumnUpdater.java     |   4 +-
 .../CollectionMultiTenantFilterBinder.java         |   3 +-
 .../secondpass/CollectionOrderByBinder.java        |   3 +-
 .../secondpass/CollectionSecondPassBinder.java     |  29 +--
 .../secondpass/CollectionWithJoinTableBinder.java  |  10 +-
 .../domainbinding/secondpass/ListSecondPass.java   |   2 +-
 .../secondpass/ListSecondPassBinder.java           |   6 +-
 .../secondpass/ManyToManyElementBinder.java        |   5 +-
 .../domainbinding/secondpass/MapSecondPass.java    |   3 +-
 .../secondpass/MapSecondPassBinder.java            |   6 +-
 .../domainbinding/secondpass/SetSecondPass.java    |   2 +-
 .../secondpass/UnidirectionalOneToManyBinder.java  |   5 +-
 ...UnidirectionalOneToManyInverseValuesBinder.java |   3 +-
 .../CollectionForPropertyConfigBinderSpec.groovy   |   3 +-
 .../cfg/domainbinding/EnumTypeBinderSpec.groovy    | 213 ++++++---------------
 .../BasicCollectionElementBinderSpec.groovy        |   8 +-
 .../BidirectionalMapElementBinderSpec.groovy       |   4 +-
 .../secondpass/CollectionKeyBinderSpec.groovy      |  16 +-
 .../CollectionMultiTenantFilterBinderSpec.groovy   |  16 +-
 .../secondpass/CollectionOrderByBinderSpec.groovy  |  20 +-
 .../CollectionWithJoinTableBinderSpec.groovy       |  16 +-
 .../secondpass/ListSecondPassBinderSpec.groovy     |   4 +-
 .../secondpass/ManyToManyElementBinderSpec.groovy  |   8 +-
 .../secondpass/MapSecondPassBinderSpec.groovy      |   8 +-
 .../UnidirectionalOneToManyBinderSpec.groovy       |  27 +--
 ...ectionalOneToManyInverseValuesBinderSpec.groovy |   8 +-
 33 files changed, 225 insertions(+), 244 deletions(-)

diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
index bb96a1df23..40197a3f0c 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
@@ -167,7 +167,7 @@ public class CollectionBinder {
             collection.setElement(oneToMany);
             bindOneToMany((HibernateOneToManyProperty) property, oneToMany);
         } else {
-            bindCollectionTable(property, collection, owner.getTable());
+            bindCollectionTable(property, owner.getTable());
 
             if (property.isBidirectional()) {
                 if (!property.isOwningSide()) {
@@ -207,8 +207,8 @@ public class CollectionBinder {
         one.setIgnoreNotFound(true);
     }
 
-    private void bindCollectionTable(HibernateToManyProperty property, 
Collection collection, Table ownerTable) {
-
+    private void bindCollectionTable(HibernateToManyProperty property, Table 
ownerTable) {
+        Collection collection = property.getCollection();
         String owningTableSchema = ownerTable.getSchema();
         PropertyConfig config = property.getMappedForm();
         JoinTable jt = config.getJoinTable();
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionForPropertyConfigBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionForPropertyConfigBinder.java
index 5980459628..a1b1e47a31 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionForPropertyConfigBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionForPropertyConfigBinder.java
@@ -31,8 +31,8 @@ import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyPrope
 public class CollectionForPropertyConfigBinder {
 
     /** Bind collection for property config. */
-    public void bindCollectionForPropertyConfig(
-            @Nonnull Collection collection, @Nonnull HibernateToManyProperty 
property) {
+    public void bindCollectionForPropertyConfig(@Nonnull 
HibernateToManyProperty property) {
+        Collection collection = property.getCollection();
         collection.setLazy(!FetchMode.JOIN.equals(property.getFetchMode()));
         
Optional.ofNullable(property.getLazy()).ifPresent(collection::setExtraLazy);
     }
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 f933ca6451..9dc940fdae 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
@@ -33,7 +33,9 @@ import org.slf4j.LoggerFactory;
 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.HibernateEnumProperty;
 import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernatePersistentProperty;
+import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty;
 import 
org.grails.orm.hibernate.cfg.domainbinding.util.ColumnNameForPropertyAndPathFetcher;
 import org.grails.orm.hibernate.cfg.domainbinding.util.GrailsEnumType;
 
@@ -70,14 +72,16 @@ public class EnumTypeBinder {
     private static final Logger LOG = 
LoggerFactory.getLogger(EnumTypeBinder.class);
 
     public BasicValue bindEnumType(
-            @Nonnull HibernatePersistentProperty property, Class<?> 
propertyType, Table table, String path) {
+            @Nonnull HibernateEnumProperty property, Class<?> propertyType, 
Table table, String path) {
         String columnName = 
columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(property, 
path, null);
-        return bindEnumTypeForColumn(property, propertyType, table, 
columnName);
+        BasicValue simpleValue = new BasicValue(metadataBuildingContext, 
property.getTable());
+        bindEnumType(property, propertyType, simpleValue, columnName);
+        return simpleValue;
     }
 
     public BasicValue bindEnumTypeForColumn(
-            @Nonnull HibernatePersistentProperty property, Class<?> 
propertyType, Table table, @Nonnull String columnName) {
-        BasicValue simpleValue = new BasicValue(metadataBuildingContext, 
table);
+            @Nonnull HibernateToManyProperty property, Class<?> propertyType, 
Table table, @Nonnull String columnName) {
+        BasicValue simpleValue = new BasicValue(metadataBuildingContext, 
property.getTable());
         bindEnumType(property, propertyType, simpleValue, columnName);
         return simpleValue;
     }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java
index a4fda2cd88..ef6db12b79 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java
@@ -74,8 +74,8 @@ public class GrailsPropertyBinder {
         Value value;
 
         // 1. Create Value and apply binders (consolidated block)
-        if (currentGrailsProp instanceof HibernateEnumProperty) {
-            value = enumTypeBinder.bindEnumType(currentGrailsProp, 
currentGrailsProp.getType(), table, path);
+        if (currentGrailsProp instanceof HibernateEnumProperty 
hibernateEnumProperty) {
+            value = enumTypeBinder.bindEnumType(hibernateEnumProperty, 
currentGrailsProp.getType(), table, path);
         } else if (currentGrailsProp instanceof HibernateOneToOneProperty 
oneToOne
                 && oneToOne.isValidHibernateOneToOne()) {
             value = oneToOneBinder.bindOneToOne(oneToOne, path);
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java
index cc8143689e..77ba8313ac 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java
@@ -64,7 +64,8 @@ public class BasicCollectionElementBinder {
     }
 
     /** Creates and binds a {@link BasicValue} element for the given basic 
collection property. */
-    public BasicValue bind(HibernateToManyProperty property, Collection 
collection) {
+    public BasicValue bind(HibernateToManyProperty property) {
+        Collection collection = property.getCollection();
         final Class<?> referencedType = property.getComponentType();
         final boolean isEnum = referencedType.isEnum();
         var joinColumnMappingOptional =
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinder.java
index 299fec1a84..5d76c1320c 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinder.java
@@ -42,11 +42,12 @@ public class BidirectionalMapElementBinder {
     }
 
     /** Binds the ManyToOne element for a bidirectional Map collection. */
-    public void bind(HibernateToManyProperty property, Collection collection) {
+    public void bind(HibernateToManyProperty property) {
+        Collection collection = property.getCollection();
         HibernateManyToOneProperty otherSide = (HibernateManyToOneProperty) 
property.getHibernateInverseSide();
         ManyToOne element = manyToOneBinder.bindManyToOne(otherSide, 
collection.getCollectionTable(), EMPTY_PATH);
         element.setReferencedEntityName(otherSide.getOwner().getName());
         collection.setElement(element);
-        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(collection, 
property);
+        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(property);
     }
 }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinder.java
index 66809152dc..d0b2443aef 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinder.java
@@ -51,7 +51,8 @@ public class CollectionKeyBinder {
 
     /** Creates the {@link DependantValue} key, sets it on the collection, and 
binds it. */
     public DependantValue bind(
-            HibernateToManyProperty property, PersistentClass associatedClass, 
Collection collection) {
+            HibernateToManyProperty property, PersistentClass associatedClass) 
{
+        Collection collection = property.getCollection();
         DependantValue key = 
primaryKeyValueCreator.createPrimaryKeyValue(collection);
         collection.setKey(key);
         if (property.isBidirectional()) {
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
index dc45acce47..c8b73d679b 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
@@ -37,8 +37,8 @@ public class CollectionKeyColumnUpdater {
     }
 
     /** Creates the key, sets it on the collection, and updates its columns. */
-    public void bind(HibernateToManyProperty property, PersistentClass 
associatedClass, Collection collection) {
-        DependantValue key = collectionKeyBinder.bind(property, 
associatedClass, collection);
+    public void bind(HibernateToManyProperty property, PersistentClass 
associatedClass) {
+        DependantValue key = collectionKeyBinder.bind(property, 
associatedClass);
         forceNullableAndCheckUpdatable(key, property);
     }
 
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinder.java
index 8625b0572c..25f006d573 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinder.java
@@ -39,7 +39,8 @@ public class CollectionMultiTenantFilterBinder {
     }
 
     /** Applies the multi-tenant filter to the collection if the associated 
entity is multi-tenant. */
-    public void bind(HibernateToManyProperty property, Collection collection) {
+    public void bind(HibernateToManyProperty property) {
+        Collection collection = property.getCollection();
         Optional.ofNullable(property.getHibernateAssociatedEntity())
                 .filter(referenced -> !(property instanceof 
HibernateManyToManyProperty) && referenced.isMultiTenant())
                 .map(referenced -> 
referenced.getMultiTenantFilterCondition(defaultColumnNameFetcher))
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinder.java
index d92e1d27eb..9dbf536913 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinder.java
@@ -42,7 +42,8 @@ public class CollectionOrderByBinder {
     }
 
     /** Binds the order-by clause and discriminator where condition to the 
given collection. */
-    public void bind(HibernateToManyProperty property, Collection collection, 
PersistentClass associatedClass) {
+    public void bind(HibernateToManyProperty property, PersistentClass 
associatedClass) {
+        Collection collection = property.getCollection();
         GrailsHibernatePersistentEntity referenced = 
property.getHibernateAssociatedEntity();
 
         if (referenced.isTablePerHierarchySubclass()) {
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
index f097040a8f..315c28ada7 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
@@ -67,24 +67,25 @@ public class CollectionSecondPassBinder {
     /** Bind collection second pass. */
     public void bindCollectionSecondPass(
             @Nonnull HibernateToManyProperty property,
-            Map<?, ?> persistentClasses,
-            @Nonnull Collection collection) {
+            Map<?, ?> persistentClasses) {
 
+        Collection collection = property.getCollection();
         PersistentClass associatedClass = resolveAssociatedClass(property, 
persistentClasses);
-        collectionOrderByBinder.bind(property, collection, associatedClass);
-        bindOneToManyAssociation(property, associatedClass, collection);
+        collectionOrderByBinder.bind(property, associatedClass);
+        bindOneToManyAssociation(property, associatedClass);
 
-        collectionMultiTenantFilterBinder.bind(property, collection);
+        collectionMultiTenantFilterBinder.bind(property);
         collection.setSorted(property.isSorted());
 
-        collectionKeyColumnUpdater.bind(property, associatedClass, collection);
+        collectionKeyColumnUpdater.bind(property, associatedClass);
         collection.setCacheConcurrencyStrategy(property.getCacheUsage());
 
-        bindCollectionElement(property, collection);
+        bindCollectionElement(property);
     }
 
     private void bindOneToManyAssociation(
-            HibernateToManyProperty property, PersistentClass associatedClass, 
Collection collection) {
+            HibernateToManyProperty property, PersistentClass associatedClass) 
{
+        Collection collection = property.getCollection();
         if (!collection.isOneToMany()) {
             return;
         }
@@ -93,20 +94,20 @@ public class CollectionSecondPassBinder {
         if (property.shouldBindWithForeignKey()) {
             collection.setCollectionTable(associatedClass.getTable());
         }
-        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(collection, 
property);
+        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(property);
     }
 
     private void bindCollectionElement(
-            HibernateToManyProperty property, Collection collection) {
+            HibernateToManyProperty property) {
         if (property instanceof HibernateManyToManyProperty manyToMany && 
manyToMany.isBidirectional()) {
-            manyToManyElementBinder.bind(manyToMany, collection);
+            manyToManyElementBinder.bind(manyToMany);
         } else if (property.isBidirectionalOneToManyMap() && 
property.isBidirectional()) {
-            bidirectionalMapElementBinder.bind(property, collection);
+            bidirectionalMapElementBinder.bind(property);
         } else if (property instanceof HibernateOneToManyProperty 
oneToManyProperty
                 && oneToManyProperty.isUnidirectionalOneToMany()) {
-            unidirectionalOneToManyBinder.bind(oneToManyProperty, collection);
+            unidirectionalOneToManyBinder.bind(oneToManyProperty);
         } else if (property.supportsJoinColumnMapping()) {
-            
collectionWithJoinTableBinder.bindCollectionWithJoinTable(property, collection);
+            
collectionWithJoinTableBinder.bindCollectionWithJoinTable(property);
         }
     }
 
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 27d597c189..e60cd87aa8 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
@@ -58,14 +58,14 @@ public class CollectionWithJoinTableBinder {
     }
 
     /** Bind collection with join table. */
-    public void bindCollectionWithJoinTable(@Nonnull HibernateToManyProperty 
property, @Nonnull Collection collection) {
-
+    public void bindCollectionWithJoinTable(@Nonnull HibernateToManyProperty 
property) {
+        Collection collection = property.getCollection();
         collection.setInverse(false);
         SimpleValue element;
         if (property.isBasic()) {
-            element = basicCollectionElementBinder.bind(property, collection);
+            element = basicCollectionElementBinder.bind(property);
         } else {
-            element = 
unidirectionalOneToManyInverseValuesBinder.bind(property, collection);
+            element = 
unidirectionalOneToManyInverseValuesBinder.bind(property);
             final var domainClass = property.getHibernateAssociatedEntity();
             if (domainClass != null) {
                 if (domainClass.getHibernateCompositeIdentity().isPresent()) {
@@ -81,6 +81,6 @@ public class CollectionWithJoinTableBinder {
         }
 
         collection.setElement(element);
-        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(collection, 
property);
+        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(property);
     }
 }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
index d1dee8d2e6..54b81bcf29 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
@@ -45,7 +45,7 @@ public class ListSecondPass implements 
org.hibernate.boot.spi.SecondPass, Grails
 
     @Override
     public void doSecondPass(Map persistentClasses) throws MappingException {
-        listSecondPassBinder.bindListSecondPass(property, persistentClasses, 
(org.hibernate.mapping.List) property.getCollection());
+        listSecondPassBinder.bindListSecondPass(property, persistentClasses);
         createCollectionKeys(property.getCollection());
     }
 }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
index e7faee3a26..ec1471d028 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
@@ -27,6 +27,7 @@ import org.hibernate.boot.spi.InFlightMetadataCollector;
 import org.hibernate.boot.spi.MetadataBuildingContext;
 import org.hibernate.mapping.Backref;
 import org.hibernate.mapping.BasicValue;
+import org.hibernate.mapping.Collection;
 import org.hibernate.mapping.DependantValue;
 import org.hibernate.mapping.IndexBackref;
 import org.hibernate.mapping.List;
@@ -69,9 +70,10 @@ public class ListSecondPassBinder {
     }
 
     public void bindListSecondPass(
-            @Nonnull HibernateToManyProperty property, Map<?, ?> 
persistentClasses, @Nonnull List list) {
+            @Nonnull HibernateToManyProperty property, Map<?, ?> 
persistentClasses) {
 
-        collectionSecondPassBinder.bindCollectionSecondPass(property, 
persistentClasses, list);
+        List list = (List) property.getCollection();
+        collectionSecondPassBinder.bindCollectionSecondPass(property, 
persistentClasses);
         String columnName = property.getIndexColumnName(namingStrategy);
         final boolean isManyToMany = property instanceof 
HibernateManyToManyProperty;
 
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinder.java
index 7b7b65610d..e6a7344657 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinder.java
@@ -41,12 +41,13 @@ public class ManyToManyElementBinder {
     }
 
     /** Binds the ManyToOne element for a bidirectional many-to-many 
collection. */
-    public void bind(HibernateManyToManyProperty manyToMany, Collection 
collection) {
+    public void bind(HibernateManyToManyProperty manyToMany) {
+        Collection collection = manyToMany.getCollection();
         HibernateManyToManyProperty otherSide = 
manyToMany.getHibernateInverseSide();
         ManyToOne element = manyToOneBinder.bindManyToOne(otherSide, 
collection.getCollectionTable(), EMPTY_PATH);
         element.setReferencedEntityName(otherSide.getOwner().getName());
         collection.setElement(element);
-        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(collection, 
manyToMany);
+        
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(manyToMany);
         if (manyToMany.isCircular()) {
             collection.setInverse(false);
         }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
index 1ba1e856a0..814c7a0a63 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
@@ -45,8 +45,7 @@ public class MapSecondPass implements 
org.hibernate.boot.spi.SecondPass, GrailsS
 
     @Override
     public void doSecondPass(Map persistentClasses) throws MappingException {
-        mapSecondPassBinder.bindMapSecondPass(
-                property, persistentClasses, (org.hibernate.mapping.Map) 
property.getCollection());
+        mapSecondPassBinder.bindMapSecondPass(property, persistentClasses);
         createCollectionKeys(property.getCollection());
     }
 }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
index 761fe0c7f0..4577e291b4 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
@@ -66,9 +66,9 @@ public class MapSecondPassBinder {
 
     public void bindMapSecondPass(
             @Nonnull HibernateToManyProperty property,
-            Map<?, ?> persistentClasses,
-            @Nonnull org.hibernate.mapping.Map map) {
-        collectionSecondPassBinder.bindCollectionSecondPass(property, 
persistentClasses, map);
+            Map<?, ?> persistentClasses) {
+        org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) 
property.getCollection();
+        collectionSecondPassBinder.bindCollectionSecondPass(property, 
persistentClasses);
 
         String type = property.getIndexColumnType("string");
         String columnName1 = property.getIndexColumnName(namingStrategy);
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
index 40a500ee27..6ae2297e0a 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
@@ -51,7 +51,7 @@ public class SetSecondPass implements 
org.hibernate.boot.spi.SecondPass, GrailsS
     }
 
     public void doSecondPass(Map persistentClasses) throws MappingException {
-        collectionSecondPassBinder.bindCollectionSecondPass(property, 
persistentClasses, property.getCollection());
+        collectionSecondPassBinder.bindCollectionSecondPass(property, 
persistentClasses);
         createCollectionKeys(property.getCollection());
     }
 }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinder.java
index faab4e2dd0..3c8d76fb34 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinder.java
@@ -49,9 +49,10 @@ public class UnidirectionalOneToManyBinder {
         this.mappings = mappings;
     }
 
-    public void bind(@Nonnull HibernateOneToManyProperty property, @Nonnull 
Collection collection) {
+    public void bind(@Nonnull HibernateOneToManyProperty property) {
+        Collection collection = property.getCollection();
         if (!property.shouldBindWithForeignKey()) {
-            
collectionWithJoinTableBinder.bindCollectionWithJoinTable(property, collection);
+            
collectionWithJoinTableBinder.bindCollectionWithJoinTable(property);
         } else {
             bindUnidirectionalOneToMany(property, collection);
         }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinder.java
index 4fff8cba45..5b84d49e56 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinder.java
@@ -36,7 +36,8 @@ public class UnidirectionalOneToManyInverseValuesBinder {
         this.metadataBuildingContext = metadataBuildingContext;
     }
 
-    public ManyToOne bind(HibernateToManyProperty property, Collection 
collection) {
+    public ManyToOne bind(HibernateToManyProperty property) {
+        Collection collection = property.getCollection();
         ManyToOne manyToOne = new ManyToOne(metadataBuildingContext, 
collection.getCollectionTable());
         manyToOne.setIgnoreNotFound(property.getIgnoreNotFound());
         manyToOne.setLazy(!FetchMode.JOIN.equals(property.getFetchMode()));
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionForPropertyConfigBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionForPropertyConfigBinderSpec.groovy
index ab3b095d53..be9bcf31ff 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionForPropertyConfigBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionForPropertyConfigBinderSpec.groovy
@@ -32,9 +32,10 @@ class CollectionForPropertyConfigBinderSpec extends 
HibernateGormDatastoreSpec {
         and: "the property is stubbed"
         property.getFetchMode() >> fetchMode
         property.getLazy() >> lazySetting
+        property.getCollection() >> collection
 
         when: "the binder is applied"
-        binder.bindCollectionForPropertyConfig(collection, property)
+        binder.bindCollectionForPropertyConfig(property)
 
         then: "the collection's lazy and extraLazy properties are set 
according to the binder's logic"
         collection.isLazy() == expectedIsLazy
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 037a67579c..2c7d7f3c3e 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
@@ -3,10 +3,11 @@ package org.grails.orm.hibernate.cfg.domainbinding
 import grails.gorm.specs.HibernateGormDatastoreSpec
 import grails.persistence.Entity
 import org.grails.datastore.mapping.model.PersistentProperty
-import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernatePersistentProperty
+import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateEnumProperty
 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.hibernate.HibernateToManyProperty
 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
@@ -14,6 +15,7 @@ import 
org.hibernate.engine.spi.SharedSessionContractImplementor
 import org.hibernate.mapping.BasicValue
 import org.hibernate.mapping.Column
 import org.hibernate.mapping.Table
+import org.hibernate.mapping.RootClass
 import org.hibernate.usertype.UserType
 import spock.lang.Subject
 import spock.lang.Unroll
@@ -25,12 +27,10 @@ import java.sql.SQLException
 import 
org.grails.orm.hibernate.cfg.domainbinding.binder.ColumnConfigToColumnBinder
 import org.grails.orm.hibernate.cfg.domainbinding.binder.EnumTypeBinder
 import org.grails.orm.hibernate.cfg.domainbinding.binder.IndexBinder
+import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentEntity
 
 class EnumTypeBinderSpec extends HibernateGormDatastoreSpec {
 
-
-
-
     def indexBinder = Mock(IndexBinder)
     def columnBinder = Mock(ColumnConfigToColumnBinder)
 
@@ -46,18 +46,29 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec 
{
         binder = new EnumTypeBinder(metadataBuildingContext, 
columnNameFetcher, indexBinder, columnBinder)
     }
 
+    /**
+     * Helper to prevent the NullPointerException by linking the GORM entity
+     * to a Hibernate RootClass/Table.
+     */
+    private PersistentProperty setupEntity(Class clazz, Table table) {
+        def grailsDomainBinder = getGrailsDomainBinder()
+        def owner = createPersistentEntity(clazz, grailsDomainBinder) as 
GrailsHibernatePersistentEntity
 
+        def rootClass = new 
RootClass(grailsDomainBinder.getMetadataBuildingContext())
+        rootClass.setTable(table)
+        owner.setPersistentClass(rootClass)
+
+        return owner.getPropertyByName("status")
+    }
 
     @Unroll
     def "should bind enum type as #expectedHibernateType when mapping 
specifies enumType as '#enumTypeMapping'"() {
         given: "A root entity and its enum property"
-        def grailsDomainBinder = getGrailsDomainBinder()
-        def owner = createPersistentEntity(clazz, grailsDomainBinder)
-        PersistentProperty property = owner.getPropertyByName("status")
         def table = new Table("person")
+        PersistentProperty property = setupEntity(clazz, table)
 
         when: "the enum is bound"
-        def simpleValue = binder.bindEnumTypeForColumn(property as 
HibernatePersistentProperty, Status01, table, "status_col")
+        def simpleValue = binder.bindEnumTypeForColumn(property as 
HibernateToManyProperty, Status01, table, "status_col")
 
         then: "the correct hibernate type is set"
         simpleValue.getTypeName() == expectedHibernateType
@@ -76,19 +87,15 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec 
{
         Person05 | UserTypeEnumType | UserTypeEnumType.class.getName()        
| null              | false
     }
 
-
-
-
     @Unroll
-    def "should set column nullability "() {
+    def "should set column nullability"() {
         given: "A root entity and its enum property"
-        def grailsDomainBinder = getGrailsDomainBinder()
-        def owner = createPersistentEntity( clazz, grailsDomainBinder)
-        PersistentProperty property = owner.getPropertyByName("status")
         def table = new Table("person")
         def columnName = "status_col"
+        PersistentProperty property = setupEntity(clazz, table)
+
         when: "the enum is bound"
-        def simpleValue = binder.bindEnumTypeForColumn(property as 
HibernatePersistentProperty, Status01, table, columnName)
+        def simpleValue = binder.bindEnumTypeForColumn(property as 
HibernateToManyProperty, Status01, table, columnName)
 
         then:
         table.columns.size() == 1
@@ -98,28 +105,23 @@ class EnumTypeBinderSpec extends 
HibernateGormDatastoreSpec {
         table.columns[0].getName() == columnName
 
         where:
-        clazz | nullable
-        Person01| false
-        Person02| true
-        Clown01 | true
-        Clown02 | true
-        Clown03 | true
-
+        clazz    | nullable
+        Person01 | false
+        Person02 | true
+        Clown01  | true
+        Clown02  | true
+        Clown03  | true
     }
 
     @Unroll
     def "should bind index and column constraints only when a column config is 
present"() {
         given: "A root entity and its enum property"
-        // This test assumes 'indexBinder' and 'columnBinder' are mocked 
collaborators
-        // injected via a setup() block, as they are created inside the binder.
-        def grailsDomainBinder = getGrailsDomainBinder()
-        def owner = createPersistentEntity(clazz, grailsDomainBinder)
-        PersistentProperty property = owner.getPropertyByName("status")
         def table = new Table("person")
         def columnName = "status_col"
+        PersistentProperty property = setupEntity(clazz, table)
 
         when: "the enum is bound"
-        binder.bindEnumTypeForColumn(property as HibernatePersistentProperty, 
Status01, table, columnName)
+        binder.bindEnumTypeForColumn(property as HibernateToManyProperty, 
Status01, table, columnName)
 
         then: "the index and column binders are invoked the correct number of 
times"
         times * indexBinder.bindIndex(columnName, _ as Column, _, table)
@@ -133,16 +135,11 @@ class EnumTypeBinderSpec extends 
HibernateGormDatastoreSpec {
 
     def "should create BasicValue and bind enum type"() {
         given: "A root entity and its enum property"
-        def grailsDomainBinder = getGrailsDomainBinder()
-        def owner = createPersistentEntity(Person01, grailsDomainBinder) as 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentEntity
-        PersistentProperty property = owner.getPropertyByName("status")
         def table = new Table("person")
-        def rootClass = new 
org.hibernate.mapping.RootClass(grailsDomainBinder.getMetadataBuildingContext())
-        rootClass.setTable(table)
-        owner.setPersistentClass(rootClass)
+        PersistentProperty property = setupEntity(Person01, table)
 
         when: "the enum is bound using the new signature"
-        def result = binder.bindEnumType(property as 
HibernatePersistentProperty, Status01, table, "")
+        def result = binder.bindEnumType(property as HibernateEnumProperty, 
Status01, table, "")
 
         then: "a BasicValue is returned and bound correctly"
         result instanceof BasicValue
@@ -152,132 +149,48 @@ class EnumTypeBinderSpec extends 
HibernateGormDatastoreSpec {
         result.getColumns().size() == 1
         result.getColumns()[0].getName() == "status"
     }
-
-
-
 }
 
-class UserTypeEnumType implements UserType {
-
-    @Override
-    int getSqlType() {
-        return 0
-    }
-
-    @Override
-    Class returnedClass() {
-        return null
-    }
-
-    @Override
-    boolean equals(Object x, Object y) {
-        return false
-    }
-
-    @Override
-    int hashCode(Object x) {
-        return 0
-    }
-
-    @Override
-    Object nullSafeGet(ResultSet rs, int position, 
SharedSessionContractImplementor session, @Deprecated Object owner) throws 
SQLException {
-        return null
-    }
-
-    @Override
-    void nullSafeSet(PreparedStatement st, Object value, int index, 
SharedSessionContractImplementor session) throws SQLException {
+// --- Supporting Classes ---
 
-    }
-
-    @Override
-    Object deepCopy(Object value) {
-        return null
-    }
-
-    @Override
-    boolean isMutable() {
-        return false
-    }
-
-    @Override
-    Serializable disassemble(Object value) {
-        return null
-    }
-
-    @Override
-    Object assemble(Serializable cached, Object owner) {
-        return null
-    }
+class UserTypeEnumType implements UserType {
+    @Override int getSqlType() { 0 }
+    @Override Class returnedClass() { null }
+    @Override boolean equals(Object x, Object y) { false }
+    @Override int hashCode(Object x) { 0 }
+    @Override Object nullSafeGet(ResultSet rs, int position, 
SharedSessionContractImplementor session, Object owner) throws SQLException { 
null }
+    @Override void nullSafeSet(PreparedStatement st, Object value, int index, 
SharedSessionContractImplementor session) throws SQLException {}
+    @Override Object deepCopy(Object value) { null }
+    @Override boolean isMutable() { false }
+    @Override Serializable disassemble(Object value) { null }
+    @Override Object assemble(Serializable cached, Object owner) { null }
 }
 
-enum Status01 {
-    AVAILABLE, OUT_OF_STOCK
-}
+enum Status01 { AVAILABLE, OUT_OF_STOCK }
 
 enum Status02 {
     FOO(3), BAR(5)
     Long id
-    Status02(Long id) {
-        this.id = id
-    }
+    Status02(Long id) { this.id = id }
 }
 
-@Entity
-class Person01 {
-    Long id
-    Status01 status
+@Entity class Person01 { Long id; Status01 status }
+@Entity class Person02 {
+    Long id; Status01 status
+    static mapping = { status enumType: "string", nullable: true }
 }
-
-@Entity
-class Person02 {
-    Long id
-    Status01 status
-    static mapping = {
-        status enumType: "string", nullable :true
-
-    }
+@Entity class Person03 {
+    Long id; Status01 status
+    static mapping = { status enumType: "ordinal", nullable: true; 
tablePerHierarchy false }
 }
-
-@Entity
-class Person03 {
-    Long id
-    Status01 status
-    static mapping = {
-        status enumType: "ordinal", nullable :true
-        tablePerHierarchy false
-
-    }
-}
-
-@Entity
-class Person04 {
-    Long id
-    Status02 status
-    static mapping = {
-        status enumType: 'identity'
-    }
+@Entity class Person04 {
+    Long id; Status02 status
+    static mapping = { status enumType: 'identity' }
 }
-
-@Entity
-class Person05 {
-    Long id
-    Status02 status
-    static mapping = {
-        status type: UserTypeEnumType
-    }
-}
-
-@Entity
-class Clown01 extends Person01 {
-    String clownName
-}
-
-@Entity
-class Clown02 extends Person02 {
-    String clownName
+@Entity class Person05 {
+    Long id; Status02 status
+    static mapping = { status type: UserTypeEnumType }
 }
-
-@Entity
-class Clown03 extends Person03 {
-    String clownName
-}
\ No newline at end of file
+@Entity class Clown01 extends Person01 { String clownName }
+@Entity class Clown02 extends Person02 { String clownName }
+@Entity class Clown03 extends Person03 { String clownName }
\ No newline at end of file
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy
index 8ea3cb4822..4e3e35b933 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy
@@ -47,8 +47,10 @@ class BasicCollectionElementBinderSpec extends 
HibernateGormDatastoreSpec {
         HibernateToManyProperty property = (HibernateToManyProperty) 
entity.getPropertyByName("tags")
         Collection collection = collectionWithTable("bceb_author_tags")
 
+        property.setCollection(collection)
+
         when:
-        BasicValue element = binder.bind(property, collection)
+        BasicValue element = binder.bind(property)
 
         then:
         element != null
@@ -62,8 +64,10 @@ class BasicCollectionElementBinderSpec extends 
HibernateGormDatastoreSpec {
         HibernateToManyProperty property = (HibernateToManyProperty) 
entity.getPropertyByName("statuses")
         Collection collection = collectionWithTable("bceb_author_statuses")
 
+        property.setCollection(collection)
+
         when:
-        BasicValue element = binder.bind(property, collection)
+        BasicValue element = binder.bind(property)
 
         then:
         element != null
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinderSpec.groovy
index 409701a4b3..2f9c942457 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BidirectionalMapElementBinderSpec.groovy
@@ -48,8 +48,10 @@ class BidirectionalMapElementBinderSpec extends 
HibernateGormDatastoreSpec {
         def collection = new Bag(mbc, null)
         collection.setCollectionTable(new Table("test", "bbme_owner_items"))
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection)
+        binder.bind(property)
 
         then:
         collection.getElement() instanceof ManyToOne
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
index 9b4332cb2f..179867af38 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
@@ -92,8 +92,10 @@ class CollectionKeyBinderSpec extends 
HibernateGormDatastoreSpec {
         def associatedClass = rootClassWith(CKBBidItem.name, "owner", 
"OWNER_ID")
         def collection = bagWithOwner(ownerRootClass("ckb_bid_owner"), 
"ckb_bid_item")
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, associatedClass, collection)
+        binder.bind(property, associatedClass)
 
         then:
         collection.isInverse()
@@ -106,8 +108,10 @@ class CollectionKeyBinderSpec extends 
HibernateGormDatastoreSpec {
         def associatedClass = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
         def collection = bagWithOwner(ownerRootClass("ckb_mtm_owner"), 
"ckb_mtm_join")
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, associatedClass, collection)
+        binder.bind(property, associatedClass)
 
         then:
         collection.getKey().getColumnSpan() > 0
@@ -120,8 +124,10 @@ class CollectionKeyBinderSpec extends 
HibernateGormDatastoreSpec {
         def associatedClass = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
         def collection = bagWithOwner(ownerRootClass("ckb_join_key_owner"), 
"ckb_join_key_owner_ckb_join_key_item")
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, associatedClass, collection)
+        binder.bind(property, associatedClass)
 
         then:
         collection.getKey().getTypeName() == "long"
@@ -135,8 +141,10 @@ class CollectionKeyBinderSpec extends 
HibernateGormDatastoreSpec {
         def associatedClass = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
         def collection = bagWithOwner(ownerRootClass("ckb_uni_owner"), 
"ckb_uni_owner_ckb_uni_item")
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, associatedClass, collection)
+        binder.bind(property, associatedClass)
 
         then:
         collection.getKey().getColumnSpan() > 0
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinderSpec.groovy
index 7442b848db..9e0f484d3b 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionMultiTenantFilterBinderSpec.groovy
@@ -49,8 +49,10 @@ class CollectionMultiTenantFilterBinderSpec extends 
HibernateGormDatastoreSpec {
         def property = propertyFor(CMTBBidirectionalOwner)
         def collection = new 
Bag(getGrailsDomainBinder().getMetadataBuildingContext(), null)
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection)
+        binder.bind(property)
 
         then:
         collection.getFilters().any { it.getName() == 
GormProperties.TENANT_IDENTITY }
@@ -62,8 +64,10 @@ class CollectionMultiTenantFilterBinderSpec extends 
HibernateGormDatastoreSpec {
         def property = propertyFor(CMTBUnidirectionalOwner)
         def collection = new 
Bag(getGrailsDomainBinder().getMetadataBuildingContext(), null)
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection)
+        binder.bind(property)
 
         then:
         collection.getManyToManyFilters().any { it.getName() == 
GormProperties.TENANT_IDENTITY }
@@ -75,8 +79,10 @@ class CollectionMultiTenantFilterBinderSpec extends 
HibernateGormDatastoreSpec {
         def property = propertyFor(CMTBManyToManyOwner)
         def collection = new 
Bag(getGrailsDomainBinder().getMetadataBuildingContext(), null)
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection)
+        binder.bind(property)
 
         then:
         collection.getFilters().isEmpty()
@@ -88,8 +94,10 @@ class CollectionMultiTenantFilterBinderSpec extends 
HibernateGormDatastoreSpec {
         def property = propertyFor(CMTBNonTenantOwner)
         def collection = new 
Bag(getGrailsDomainBinder().getMetadataBuildingContext(), null)
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection)
+        binder.bind(property)
 
         then:
         collection.getFilters().isEmpty()
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinderSpec.groovy
index 87a8819c0c..632aadd3ec 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionOrderByBinderSpec.groovy
@@ -57,8 +57,10 @@ class CollectionOrderByBinderSpec extends 
HibernateGormDatastoreSpec {
         property.getMappedForm().setSort("value")
         property.getMappedForm().setOrder("desc")
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection, associatedClass)
+        binder.bind(property, associatedClass)
 
         then:
         collection.getOrderBy() != null
@@ -73,8 +75,10 @@ class CollectionOrderByBinderSpec extends 
HibernateGormDatastoreSpec {
         def associatedClass = rootClassWith(COBAssociatedItem.name, "value", 
"VALUE")
         property.getMappedForm().setSort("value")
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection, associatedClass)
+        binder.bind(property, associatedClass)
 
         then:
         collection.getOrderBy() != null
@@ -88,8 +92,10 @@ class CollectionOrderByBinderSpec extends 
HibernateGormDatastoreSpec {
         def associatedClass = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
         property.getMappedForm().setSort("value")
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection, associatedClass)
+        binder.bind(property, associatedClass)
 
         then:
         thrown(DatastoreConfigurationException)
@@ -101,8 +107,10 @@ class CollectionOrderByBinderSpec extends 
HibernateGormDatastoreSpec {
         def collection = new 
Bag(getGrailsDomainBinder().getMetadataBuildingContext(), null)
         def associatedClass = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection, associatedClass)
+        binder.bind(property, associatedClass)
 
         then:
         collection.getOrderBy() == null
@@ -114,8 +122,10 @@ class CollectionOrderByBinderSpec extends 
HibernateGormDatastoreSpec {
         def collection = new 
Bag(getGrailsDomainBinder().getMetadataBuildingContext(), null)
         def associatedClass = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection, associatedClass)
+        binder.bind(property, associatedClass)
 
         then:
         collection.getWhere() != null
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinderSpec.groovy
index 8bfb4954fc..29d58aac6b 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinderSpec.groovy
@@ -51,15 +51,16 @@ class CollectionWithJoinTableBinderSpec extends 
HibernateGormDatastoreSpec {
         collection.setCollectionTable(new Table("CWJTB_TAGS"))
 
         def basicValue = new 
org.hibernate.mapping.BasicValue(domainBinder.metadataBuildingContext, 
collection.getCollectionTable())
-        basicCollectionElementBinder.bind(property, collection) >> basicValue
+        property.setCollection(collection)
+        basicCollectionElementBinder.bind(property) >> basicValue
 
         when:
-        binder.bindCollectionWithJoinTable(property, collection)
+        binder.bindCollectionWithJoinTable(property)
 
         then:
-        1 * basicCollectionElementBinder.bind(property, collection) >> 
basicValue
+        1 * basicCollectionElementBinder.bind(property) >> basicValue
         collection.getElement() == basicValue
-        1 * 
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(collection, 
property)
+        1 * 
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(property)
     }
 
     void "test bindCollectionWithJoinTable creates ManyToOne element for 
entity association"() {
@@ -75,15 +76,16 @@ class CollectionWithJoinTableBinderSpec extends 
HibernateGormDatastoreSpec {
         Collection collection = new Set(domainBinder.metadataBuildingContext, 
owner)
         collection.setCollectionTable(new Table("CWJTB_BOOKS"))
 
+        property.setCollection(collection)
         def manyToOne = new ManyToOne(domainBinder.metadataBuildingContext, 
collection.getCollectionTable())
-        unidirectionalOneToManyInverseValuesBinder.bind(property, collection) 
>> manyToOne
+        unidirectionalOneToManyInverseValuesBinder.bind(property) >> manyToOne
 
         when:
-        binder.bindCollectionWithJoinTable(property, collection)
+        binder.bindCollectionWithJoinTable(property)
 
         then:
         collection.getElement() instanceof ManyToOne
-        1 * 
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(collection, 
property)
+        1 * 
collectionForPropertyConfigBinder.bindCollectionForPropertyConfig(property)
     }
 }
 
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy
index bfbf04d353..5cddb03857 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy
@@ -235,8 +235,10 @@ class ListSecondPassBinderSpec extends 
HibernateGormDatastoreSpec {
         element.setReferencedEntityName(LSBBook.name)
         list.setElement(element)
 
+        booksProp.setCollection(list)
+
         when:
-        listBinder.bindListSecondPass(booksProp, persistentClasses, list)
+        listBinder.bindListSecondPass(booksProp, persistentClasses)
 
         then:
         noExceptionThrown()
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinderSpec.groovy
index af397f4a2a..52a1dae3be 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToManyElementBinderSpec.groovy
@@ -50,8 +50,10 @@ class ManyToManyElementBinderSpec extends 
HibernateGormDatastoreSpec {
         def collection = new Bag(mbc, null)
         collection.setCollectionTable(new Table("test", 
"mtme_owner_mtme_item"))
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection)
+        binder.bind(property)
 
         then:
         collection.getElement() instanceof ManyToOne
@@ -65,8 +67,10 @@ class ManyToManyElementBinderSpec extends 
HibernateGormDatastoreSpec {
         def collection = new Bag(mbc, null)
         collection.setCollectionTable(new Table("test", 
"mtme_subtype_mtme_base"))
 
+        property.setCollection(collection)
+
         when:
-        binder.bind(property, collection)
+        binder.bind(property)
 
         then:
         property.isCircular()
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy
index 7c77072f58..fd0f8a4966 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy
@@ -197,8 +197,10 @@ class MapSecondPassBinderSpec extends 
HibernateGormDatastoreSpec {
         map.setRole("${authorEntity.name}.books".toString())
         map.setCollectionTable(rootClass.getTable())
 
+        booksProp.setCollection(map)
+
         when:
-        mapBinder.bindMapSecondPass(booksProp, persistentClasses, map)
+        mapBinder.bindMapSecondPass(booksProp, persistentClasses)
 
         then:
         noExceptionThrown()
@@ -249,8 +251,10 @@ class MapSecondPassBinderSpec extends 
HibernateGormDatastoreSpec {
         element.setReferencedEntityName(MSBBook.name)
         map.setElement(element)
 
+        booksProp.setCollection(map)
+
         when:
-        mapBinder.bindMapSecondPass(booksProp, persistentClasses, map)
+        mapBinder.bindMapSecondPass(booksProp, persistentClasses)
 
         then:
         noExceptionThrown()
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy
index f3d756f127..5328d2717b 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy
@@ -81,8 +81,10 @@ class UnidirectionalOneToManyBinderSpec extends 
HibernateGormDatastoreSpec {
         collection.setElement(element)
         collection.setKey(new 
BasicValue(grailsDomainBinder.metadataBuildingContext, 
ownerPersistentClass.getTable()))
 
+        ownerToPetsProperty.setCollection(collection)
+
         when:
-        binder.bind(ownerToPetsProperty, collection)
+        binder.bind(ownerToPetsProperty)
 
         then:
         collection.isInverse() == false
@@ -96,33 +98,36 @@ class UnidirectionalOneToManyBinderSpec extends 
HibernateGormDatastoreSpec {
         def ownerEntity = 
grailsDomainBinder.hibernateMappingContext.getPersistentEntity(UniOwner.name) 
as GrailsHibernatePersistentEntity
         def petEntity = 
grailsDomainBinder.hibernateMappingContext.getPersistentEntity(UniPet.name) as 
GrailsHibernatePersistentEntity
 
-        // Use a Stub for the property to override shouldBindWithForeignKey
-        def ownerToPetsProperty = Stub(HibernateOneToManyProperty) {
-            shouldBindWithForeignKey() >> true
-            getOwner() >> ownerEntity
-            getName() >> "pets"
-        }
-
         def mappings = 
grailsDomainBinder.metadataBuildingContext.metadataCollector
         def ownerPersistentClass = mappings.getEntityBinding(UniOwner.name)
         def petPersistentClass = mappings.getEntityBinding(UniPet.name)
 
+        // 1. Initialize the collection
         def collection = new Bag(grailsDomainBinder.metadataBuildingContext, 
ownerPersistentClass)
         collection.setRole(UniOwner.name + ".pets")
 
+        // 2. IMPORTANT: Initialize and set the element (This fixes the NPE)
         def element = new 
OneToMany(grailsDomainBinder.metadataBuildingContext, ownerPersistentClass)
         element.setReferencedEntityName(petEntity.getName())
         collection.setElement(element)
-        collection.setKey(new 
BasicValue(grailsDomainBinder.metadataBuildingContext, 
ownerPersistentClass.getTable()))
+
+        // 3. Set the key (the FK column mapping on the other side)
+        collection.setKey(new 
BasicValue(grailsDomainBinder.metadataBuildingContext, 
petPersistentClass.getTable()))
+
+        def ownerToPetsProperty = Stub(HibernateOneToManyProperty) {
+            shouldBindWithForeignKey() >> true
+            getOwner() >> ownerEntity
+            getName() >> "pets"
+            getCollection() >> collection
+        }
 
         when:
-        binder.bind(ownerToPetsProperty, collection)
+        binder.bind(ownerToPetsProperty)
 
         then:
         collection.isInverse() == false
         petPersistentClass.getProperty("_UniOwner_petsBackref") != null
     }
-
 }
 
 @Entity
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinderSpec.groovy
index 0cd6035923..3af7ac48ce 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyInverseValuesBinderSpec.groovy
@@ -27,8 +27,10 @@ class UnidirectionalOneToManyInverseValuesBinderSpec extends 
HibernateGormDatast
         org.hibernate.mapping.Collection collection = new 
org.hibernate.mapping.Set(getGrailsDomainBinder().metadataBuildingContext, 
owner)
         collection.setCollectionTable(new 
org.hibernate.mapping.Table("UOTM_BOOKS"))
 
+        property.setCollection(collection)
+
         when:
-        ManyToOne manyToOne = binder.bind(property, collection)
+        ManyToOne manyToOne = binder.bind(property)
 
         then:
         manyToOne.isIgnoreNotFound() == false
@@ -46,8 +48,10 @@ class UnidirectionalOneToManyInverseValuesBinderSpec extends 
HibernateGormDatast
         org.hibernate.mapping.Collection collection = new 
org.hibernate.mapping.Set(getGrailsDomainBinder().metadataBuildingContext, 
owner)
         collection.setCollectionTable(new 
org.hibernate.mapping.Table("UOTM_BOOKS_CUSTOM"))
 
+        property.setCollection(collection)
+
         when:
-        ManyToOne manyToOne = binder.bind(property, collection)
+        ManyToOne manyToOne = binder.bind(property)
 
         then:
         manyToOne.isIgnoreNotFound() == true

Reply via email to