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 e75113a7b7cbe611a5659a53d86c0a4b45452d03 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Wed Mar 4 20:50:53 2026 -0600 cleanup(hibernate7): general clean up --- .../cfg/domainbinding/hibernate/HibernateToManyProperty.java | 8 ++++++++ .../domainbinding/secondpass/BasicCollectionElementBinder.java | 3 +-- .../cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java | 1 - .../cfg/domainbinding/secondpass/CollectionSecondPassBinder.java | 2 +- .../domainbinding/secondpass/CollectionWithJoinTableBinder.java | 3 +-- .../hibernate/cfg/domainbinding/secondpass/ListSecondPass.java | 1 - .../cfg/domainbinding/secondpass/ListSecondPassBinder.java | 5 ++--- .../orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java | 1 - .../cfg/domainbinding/secondpass/MapSecondPassBinder.java | 6 +++--- .../orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java | 1 - .../domainbinding/secondpass/UnidirectionalOneToManyBinder.java | 2 +- .../hibernate/cfg/domainbinding/util/CascadeBehaviorFetcher.java | 8 -------- .../secondpass/CollectionWithJoinTableBinderSpec.groovy | 4 ++-- 13 files changed, 19 insertions(+), 26 deletions(-) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java index 542b426b3c..3a3c1e9538 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java @@ -72,6 +72,14 @@ public interface HibernateToManyProperty return this instanceof Basic; } + /** + * Returns the component type for basic (scalar/enum) collections, or {@code null} if this is not + * a basic collection. + */ + default Class<?> getComponentType() { + return this instanceof Basic<?> basic ? basic.getComponentType() : null; + } + /** * @return Whether the collection should be bound with a foreign key */ 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 c9eafa624e..64582d4043 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 @@ -21,7 +21,6 @@ package org.grails.orm.hibernate.cfg.domainbinding.secondpass; import static org.grails.orm.hibernate.cfg.domainbinding.binder.GrailsDomainBinder.UNDERSCORE; import java.util.Optional; -import org.grails.datastore.mapping.model.types.Basic; import org.grails.orm.hibernate.cfg.ColumnConfig; import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy; import org.grails.orm.hibernate.cfg.PropertyConfig; @@ -64,7 +63,7 @@ public class BasicCollectionElementBinder { /** Creates and binds a {@link BasicValue} element for the given basic collection property. */ public BasicValue bind(HibernateToManyProperty property, Collection collection) { - final Class<?> referencedType = ((Basic) property).getComponentType(); + final Class<?> referencedType = property.getComponentType(); final boolean isEnum = referencedType.isEnum(); var joinColumnMappingOptional = Optional.ofNullable(property.getMappedForm()).map(PropertyConfig::getJoinTableColumnConfig); 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 48a1fdd5cb..393b39a6a9 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 @@ -19,7 +19,6 @@ package org.grails.orm.hibernate.cfg.domainbinding.secondpass; import java.util.Objects; -import java.util.stream.StreamSupport; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty; import org.hibernate.mapping.Collection; import org.hibernate.mapping.DependantValue; 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 26b2f34cd0..b04ac51bfa 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 @@ -110,7 +110,7 @@ public class CollectionSecondPassBinder { } else if (property instanceof HibernateOneToManyProperty oneToManyProperty && oneToManyProperty.isUnidirectionalOneToMany()) { unidirectionalOneToManyBinder.bind(oneToManyProperty, collection); } else if (property.supportsJoinColumnMapping()) { - collectionWithJoinTableBinder.bindCollectionWithJoinTable(property, mappings, collection); + collectionWithJoinTableBinder.bindCollectionWithJoinTable(property, collection); } } 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 be671fdf8f..0aa05d7e44 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 @@ -26,7 +26,7 @@ import org.grails.orm.hibernate.cfg.domainbinding.binder.CollectionForPropertyCo import org.grails.orm.hibernate.cfg.domainbinding.binder.CompositeIdentifierToManyToOneBinder; 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.mapping.*; /** Binds a collection with a join table. */ @@ -60,7 +60,6 @@ public class CollectionWithJoinTableBinder { /** Bind collection with join table. */ public void bindCollectionWithJoinTable( @Nonnull HibernateToManyProperty property, - @Nonnull InFlightMetadataCollector mappings, @Nonnull Collection collection) { collection.setInverse(false); 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 edeb426bb7..949ff4ffdd 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 @@ -47,7 +47,6 @@ public class ListSecondPass this.collection = coll; } - @SuppressWarnings("rawtypes") @Override public void doSecondPass(Map persistentClasses) throws MappingException { listSecondPassBinder.bindListSecondPass( 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 955cb90a57..4fd1d67c30 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 @@ -96,9 +96,8 @@ public class ListSecondPassBinder { String entityName; Value element = list.getElement(); - if (element instanceof ManyToOne) { - ManyToOne manyToOne = (ManyToOne) element; - entityName = manyToOne.getReferencedEntityName(); + if (element instanceof ManyToOne manyToOne) { + entityName = manyToOne.getReferencedEntityName(); } else { entityName = ((OneToMany) element).getReferencedEntityName(); } 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 47eb3593f3..07374fd533 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 @@ -47,7 +47,6 @@ public class MapSecondPass this.collection = coll; } - @SuppressWarnings("rawtypes") @Override public void doSecondPass(Map persistentClasses) throws MappingException { mapSecondPassBinder.bindMapSecondPass( 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 2d3b24df62..456d9c7c12 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 @@ -21,7 +21,6 @@ package org.grails.orm.hibernate.cfg.domainbinding.secondpass; import jakarta.annotation.Nonnull; import java.util.List; import java.util.Map; -import org.grails.datastore.mapping.model.types.Basic; import org.grails.orm.hibernate.cfg.ColumnConfig; import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy; import org.grails.orm.hibernate.cfg.PropertyConfig; @@ -89,8 +88,9 @@ public class MapSecondPassBinder { && !(property instanceof HibernateManyToManyProperty)) { String typeName = null; - if (property instanceof Basic basic) { - typeName = property.getTypeName(basic.getComponentType()); + Class<?> componentType = property.getComponentType(); + if (componentType != null) { + typeName = property.getTypeName(componentType); } if (typeName == null) { 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 cf2035451d..e19539af2f 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 @@ -54,7 +54,6 @@ public class SetSecondPass this.collection = coll; } - @SuppressWarnings("rawtypes") public void doSecondPass(Map persistentClasses) throws MappingException { collectionSecondPassBinder.bindCollectionSecondPass( property, mappings, persistentClasses, collection); 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 1e2451e616..ea335df918 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 @@ -52,7 +52,7 @@ public class UnidirectionalOneToManyBinder { @Nonnull HibernateOneToManyProperty property, @Nonnull Collection collection) { if (!property.shouldBindWithForeignKey()) { - collectionWithJoinTableBinder.bindCollectionWithJoinTable(property, mappings, collection); + collectionWithJoinTableBinder.bindCollectionWithJoinTable(property, collection); } else { bindUnidirectionalOneToMany(property, collection); } diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CascadeBehaviorFetcher.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CascadeBehaviorFetcher.java index 3b65475ee3..ba801613fe 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CascadeBehaviorFetcher.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CascadeBehaviorFetcher.java @@ -25,9 +25,7 @@ import java.util.Optional; import org.grails.datastore.mapping.model.types.Association; import org.grails.datastore.mapping.model.types.Basic; import org.grails.datastore.mapping.model.types.Embedded; -import org.grails.orm.hibernate.cfg.Mapping; import org.grails.orm.hibernate.cfg.PropertyConfig; -import org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentEntity; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateManyToManyProperty; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateManyToOneProperty; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateOneToManyProperty; @@ -102,10 +100,4 @@ public class CascadeBehaviorFetcher { } } - private Mapping getOwnersWrappedForm(Association<?> association) { - if (association.getOwner() instanceof GrailsHibernatePersistentEntity persistentEntity) { - return persistentEntity.getMappedForm(); - } - return 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 1aa0ab2809..8bfb4954fc 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 @@ -54,7 +54,7 @@ class CollectionWithJoinTableBinderSpec extends HibernateGormDatastoreSpec { basicCollectionElementBinder.bind(property, collection) >> basicValue when: - binder.bindCollectionWithJoinTable(property, mappings, collection) + binder.bindCollectionWithJoinTable(property, collection) then: 1 * basicCollectionElementBinder.bind(property, collection) >> basicValue @@ -79,7 +79,7 @@ class CollectionWithJoinTableBinderSpec extends HibernateGormDatastoreSpec { unidirectionalOneToManyInverseValuesBinder.bind(property, collection) >> manyToOne when: - binder.bindCollectionWithJoinTable(property, mappings, collection) + binder.bindCollectionWithJoinTable(property, collection) then: collection.getElement() instanceof ManyToOne
