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 244a595487a10b003f6760e3235e2f19641c079d
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Tue Mar 3 16:04:02 2026 -0600

    refactor: move ManyToOne element creation into 
UnidirectionalOneToManyInverseValuesBinder
---
 .../cfg/domainbinding/binder/CollectionBinder.java   |  3 +--
 .../secondpass/CollectionWithJoinTableBinder.java    |  9 +--------
 .../UnidirectionalOneToManyInverseValuesBinder.java  | 15 ++++++++++++---
 .../secondpass/CollectionSecondPassBinderSpec.groovy |  2 +-
 .../CollectionWithJoinTableBinderSpec.groovy         |  4 +++-
 .../UnidirectionalOneToManyBinderSpec.groovy         |  3 +--
 ...irectionalOneToManyInverseValuesBinderSpec.groovy | 20 ++++++++++++++------
 7 files changed, 33 insertions(+), 23 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 71e1bf5fb3..adea9b6d82 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
@@ -96,11 +96,10 @@ public class CollectionBinder {
     CollectionForPropertyConfigBinder collectionForPropertyConfigBinder =
         new CollectionForPropertyConfigBinder();
     UnidirectionalOneToManyInverseValuesBinder 
unidirectionalOneToManyInverseValuesBinder =
-        new UnidirectionalOneToManyInverseValuesBinder();
+        new 
UnidirectionalOneToManyInverseValuesBinder(metadataBuildingContext);
     SimpleValueColumnBinder simpleValueColumnBinder = new 
SimpleValueColumnBinder();
     CollectionWithJoinTableBinder collectionWithJoinTableBinder =
         new CollectionWithJoinTableBinder(
-            metadataBuildingContext,
             namingStrategy,
             unidirectionalOneToManyInverseValuesBinder,
             compositeIdentifierToManyToOneBinder,
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 e880b21c56..e83dea0456 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
@@ -28,15 +28,12 @@ import 
org.grails.orm.hibernate.cfg.domainbinding.binder.CompositeIdentifierToMa
 import 
org.grails.orm.hibernate.cfg.domainbinding.binder.SimpleValueColumnBinder;
 import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty;
 import org.hibernate.boot.spi.InFlightMetadataCollector;
-import org.hibernate.boot.spi.MetadataBuildingContext;
 import org.hibernate.mapping.*;
-import org.hibernate.mapping.Collection;
 
 /** Binds a collection with a join table. */
 @SuppressWarnings("PMD.DataflowAnomalyAnalysis")
 public class CollectionWithJoinTableBinder {
 
-  private final MetadataBuildingContext metadataBuildingContext;
   private final PersistentEntityNamingStrategy namingStrategy;
   private final UnidirectionalOneToManyInverseValuesBinder
       unidirectionalOneToManyInverseValuesBinder;
@@ -47,14 +44,12 @@ public class CollectionWithJoinTableBinder {
 
   /** Creates a new {@link CollectionWithJoinTableBinder} instance. */
   public CollectionWithJoinTableBinder(
-      MetadataBuildingContext metadataBuildingContext,
       PersistentEntityNamingStrategy namingStrategy,
       UnidirectionalOneToManyInverseValuesBinder 
unidirectionalOneToManyInverseValuesBinder,
       CompositeIdentifierToManyToOneBinder 
compositeIdentifierToManyToOneBinder,
       CollectionForPropertyConfigBinder collectionForPropertyConfigBinder,
       SimpleValueColumnBinder simpleValueColumnBinder,
       BasicCollectionElementBinder basicCollectionElementBinder) {
-    this.metadataBuildingContext = metadataBuildingContext;
     this.namingStrategy = namingStrategy;
     this.unidirectionalOneToManyInverseValuesBinder = 
unidirectionalOneToManyInverseValuesBinder;
     this.compositeIdentifierToManyToOneBinder = 
compositeIdentifierToManyToOneBinder;
@@ -74,9 +69,7 @@ public class CollectionWithJoinTableBinder {
     if (property.isBasic()) {
       element = basicCollectionElementBinder.bind(property, collection);
     } else {
-      element = new ManyToOne(metadataBuildingContext, 
collection.getCollectionTable());
-      
unidirectionalOneToManyInverseValuesBinder.bindUnidirectionalOneToManyInverseValues(
-          property, (ManyToOne) element);
+      element = unidirectionalOneToManyInverseValuesBinder.bind(property, 
collection);
       final var domainClass = property.getHibernateAssociatedEntity();
       if (domainClass != null) {
         var joinColumnMappingOptional =
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 a9b188fae9..1f8684e35e 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
@@ -21,16 +21,25 @@ package 
org.grails.orm.hibernate.cfg.domainbinding.secondpass;
 import java.util.Optional;
 import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty;
 import org.hibernate.FetchMode;
+import org.hibernate.boot.spi.MetadataBuildingContext;
+import org.hibernate.mapping.Collection;
 import org.hibernate.mapping.ManyToOne;
 
-/** Binds inverse values for unidirectional one-to-many associations. */
+/** Creates and binds a {@link ManyToOne} element for unidirectional to-many 
join-table associations. */
 public class UnidirectionalOneToManyInverseValuesBinder {
 
-  public void bindUnidirectionalOneToManyInverseValues(
-      HibernateToManyProperty property, ManyToOne manyToOne) {
+  private final MetadataBuildingContext metadataBuildingContext;
+
+  public UnidirectionalOneToManyInverseValuesBinder(MetadataBuildingContext 
metadataBuildingContext) {
+    this.metadataBuildingContext = metadataBuildingContext;
+  }
+
+  public ManyToOne bind(HibernateToManyProperty property, Collection 
collection) {
+    ManyToOne manyToOne = new ManyToOne(metadataBuildingContext, 
collection.getCollectionTable());
     manyToOne.setIgnoreNotFound(property.getIgnoreNotFound());
     manyToOne.setLazy(!FetchMode.JOIN.equals(property.getFetchMode()));
     Optional.ofNullable(property.getLazy()).ifPresent(manyToOne::setLazy);
     
manyToOne.setReferencedEntityName(property.getHibernateAssociatedEntity().getName());
+    return manyToOne;
   }
 }
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
index 2cd4ee88dc..66c88059fe 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
@@ -34,7 +34,7 @@ class CollectionSecondPassBinderSpec extends 
HibernateGormDatastoreSpec {
         def pkvc = new PrimaryKeyValueCreator(mbc)
         def botml = new BidirectionalOneToManyLinker(new 
org.grails.orm.hibernate.cfg.domainbinding.util.GrailsPropertyResolver())
         def dkvb = new DependentKeyValueBinder(svb, citmto)
-        def cwjtb = new CollectionWithJoinTableBinder(mbc, ns, new 
UnidirectionalOneToManyInverseValuesBinder(), citmto, new 
CollectionForPropertyConfigBinder(), new SimpleValueColumnBinder(), new 
BasicCollectionElementBinder(mbc, ns, null, new SimpleValueColumnBinder(), 
svcf, null))
+        def cwjtb = new CollectionWithJoinTableBinder(ns, new 
UnidirectionalOneToManyInverseValuesBinder(mbc), citmto, new 
CollectionForPropertyConfigBinder(), new SimpleValueColumnBinder(), new 
BasicCollectionElementBinder(mbc, ns, null, new SimpleValueColumnBinder(), 
svcf, null))
         def uotmb = new UnidirectionalOneToManyBinder(cwjtb, 
mbc.getMetadataCollector())
         def cfpcb = new CollectionForPropertyConfigBinder()
         def dcnf = new DefaultColumnNameFetcher(ns, new BackticksRemover())
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 abc62e0ebd..1aa0ab2809 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
@@ -29,7 +29,6 @@ class CollectionWithJoinTableBinderSpec extends 
HibernateGormDatastoreSpec {
     void setup() {
         def domainBinder = getGrailsDomainBinder()
         binder = new CollectionWithJoinTableBinder(
-                domainBinder.metadataBuildingContext,
                 domainBinder.namingStrategy,
                 unidirectionalOneToManyInverseValuesBinder,
                 compositeIdentifierToManyToOneBinder,
@@ -76,6 +75,9 @@ class CollectionWithJoinTableBinderSpec extends 
HibernateGormDatastoreSpec {
         Collection collection = new Set(domainBinder.metadataBuildingContext, 
owner)
         collection.setCollectionTable(new Table("CWJTB_BOOKS"))
 
+        def manyToOne = new ManyToOne(domainBinder.metadataBuildingContext, 
collection.getCollectionTable())
+        unidirectionalOneToManyInverseValuesBinder.bind(property, collection) 
>> manyToOne
+
         when:
         binder.bindCollectionWithJoinTable(property, mappings, collection)
 
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 c26c011306..f3d756f127 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
@@ -39,14 +39,13 @@ class UnidirectionalOneToManyBinderSpec extends 
HibernateGormDatastoreSpec {
         def backticksRemover = new BackticksRemover()
         def columnNameForPropertyAndPathFetcher = new 
ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, 
backticksRemover)
 
-        def unidirectionalOneToManyInverseValuesBinder = new 
UnidirectionalOneToManyInverseValuesBinder()
+        def unidirectionalOneToManyInverseValuesBinder = new 
UnidirectionalOneToManyInverseValuesBinder(metadataBuildingContext)
         def enumTypeBinder = new EnumTypeBinder(metadataBuildingContext, 
columnNameForPropertyAndPathFetcher)
         def compositeIdentifierToManyToOneBinder = new 
CompositeIdentifierToManyToOneBinder(metadataBuildingContext, namingStrategy, 
jdbcEnvironment)
         def simpleValueColumnFetcher = new SimpleValueColumnFetcher()
         def collectionForPropertyConfigBinder = new 
CollectionForPropertyConfigBinder()
 
         def collectionWithJoinTableBinder = new CollectionWithJoinTableBinder(
-                metadataBuildingContext,
                 namingStrategy,
                 unidirectionalOneToManyInverseValuesBinder,
                 compositeIdentifierToManyToOneBinder,
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 7894137c75..0cd6035923 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
@@ -11,18 +11,24 @@ import spock.lang.Subject
 class UnidirectionalOneToManyInverseValuesBinderSpec extends 
HibernateGormDatastoreSpec {
 
     @Subject
-    UnidirectionalOneToManyInverseValuesBinder binder = new 
UnidirectionalOneToManyInverseValuesBinder()
+    UnidirectionalOneToManyInverseValuesBinder binder
+
+    void setup() {
+        binder = new 
UnidirectionalOneToManyInverseValuesBinder(getGrailsDomainBinder().metadataBuildingContext)
+    }
 
     void "test bindUnidirectionalOneToManyInverseValues"() {
         given:
         createPersistentEntity(UOTMBook)
         PersistentEntity authorEntity = createPersistentEntity(UOTMAuthor)
         HibernateToManyProperty property = (HibernateToManyProperty) 
authorEntity.getPropertyByName("books")
-        
-        ManyToOne manyToOne = new 
ManyToOne(getGrailsDomainBinder().getMetadataBuildingContext(), null)
+
+        def owner = new 
org.hibernate.mapping.RootClass(getGrailsDomainBinder().metadataBuildingContext)
+        org.hibernate.mapping.Collection collection = new 
org.hibernate.mapping.Set(getGrailsDomainBinder().metadataBuildingContext, 
owner)
+        collection.setCollectionTable(new 
org.hibernate.mapping.Table("UOTM_BOOKS"))
 
         when:
-        binder.bindUnidirectionalOneToManyInverseValues(property, manyToOne)
+        ManyToOne manyToOne = binder.bind(property, collection)
 
         then:
         manyToOne.isIgnoreNotFound() == false
@@ -36,10 +42,12 @@ class UnidirectionalOneToManyInverseValuesBinderSpec 
extends HibernateGormDatast
         PersistentEntity authorEntity = 
createPersistentEntity(UOTMAuthorCustom)
         HibernateToManyProperty property = (HibernateToManyProperty) 
authorEntity.getPropertyByName("books")
 
-        ManyToOne manyToOne = new 
ManyToOne(getGrailsDomainBinder().getMetadataBuildingContext(), null)
+        def owner = new 
org.hibernate.mapping.RootClass(getGrailsDomainBinder().metadataBuildingContext)
+        org.hibernate.mapping.Collection collection = new 
org.hibernate.mapping.Set(getGrailsDomainBinder().metadataBuildingContext, 
owner)
+        collection.setCollectionTable(new 
org.hibernate.mapping.Table("UOTM_BOOKS_CUSTOM"))
 
         when:
-        binder.bindUnidirectionalOneToManyInverseValues(property, manyToOne)
+        ManyToOne manyToOne = binder.bind(property, collection)
 
         then:
         manyToOne.isIgnoreNotFound() == true

Reply via email to