This is an automated email from the ASF dual-hosted git repository. borinquenkid pushed a commit to branch 8.0.x-hibernate7 in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 8002bdbdadc36d12ef934d251c36ce86e6ca8311 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Tue Feb 3 07:25:26 2026 -0600 1. `GrailsHibernatePersistentProperty` Refactoring: * Added a no-arg getTypeName() default method that automatically uses the property owner's mapping. * Added a getTypeName(PropertyConfig config, Mapping mapping) overload to allow resolving type names for specific configurations (like index columns or join tables) while still falling back to the mapping defaults if needed. * Updated the existing getTypeName(Mapping mapping) to delegate to the new more specific overload. --- .../grails/orm/hibernate/cfg/GrailsDomainBinder.java | 12 ++++++------ .../cfg/GrailsHibernatePersistentProperty.java | 20 ++++++++++++++++++-- .../hibernate/cfg/domainbinding/EnumTypeBinder.java | 2 +- .../domainbinding/collectionType/CollectionType.java | 4 +--- .../collectionType/CollectionTypeSpec.groovy | 7 +------ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java index 554ff3f01e..41d7adbd51 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java @@ -282,7 +282,7 @@ public class GrailsDomainBinder if (domainClass != null) { mapping = domainClass.getMappedForm(); } - String typeName = property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName(mapping) : null; + String typeName = property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName() : null; if (typeName == null ) { if(property instanceof Basic) { @@ -735,7 +735,7 @@ public class GrailsDomainBinder if (domainClass != null) { mapping = domainClass.getMappedForm(); } - String typeName = property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName(mapping) : null; + String typeName = property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName() : null; if (typeName == null) { Type type = mappings.getTypeConfiguration().getBasicTypeRegistry().getRegisteredType(className); if (type != null) { @@ -1519,7 +1519,7 @@ public class GrailsDomainBinder value = new BasicValue(metadataBuildingContext, table); } else if (collectionType != null) { - String typeName = currentGrailsProp.getTypeName(gormMapping); + String typeName = currentGrailsProp.getTypeName(); if ("serializable".equals(typeName)) { value = new BasicValue(metadataBuildingContext, table); } @@ -1593,8 +1593,8 @@ public class GrailsDomainBinder String columnName = new ColumnNameForPropertyAndPathFetcher(namingStrategy).getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null); enumTypeBinder.bindEnumType(currentGrailsProp, currentGrailsProp.getType(), simpleValue, columnName); } - else if (collectionType != null && "serializable".equals(currentGrailsProp.getTypeName(gormMapping))) { - String typeName = currentGrailsProp.getTypeName(gormMapping); + else if (collectionType != null && "serializable".equals(currentGrailsProp.getTypeName())) { + String typeName = currentGrailsProp.getTypeName(); boolean nullable = currentGrailsProp.isNullable(); String columnName = new ColumnNameForPropertyAndPathFetcher(namingStrategy).getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null); new SimpleValueColumnBinder().bindSimpleValue(simpleValue, typeName, columnName, nullable); @@ -1638,7 +1638,7 @@ public class GrailsDomainBinder mapping = domainClass.getMappedForm(); } - return property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName(mapping) : null; + return ((GrailsHibernatePersistentProperty) property).getTypeName(pc.getIndexColumn(), mapping); } diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java index f9884d4017..546d9fa874 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java @@ -10,15 +10,31 @@ import java.util.Optional; public interface GrailsHibernatePersistentProperty extends PersistentProperty<PropertyConfig> { /** + * @param config The property config * @param mapping The mapping * @return The type name */ - default String getTypeName(Mapping mapping) { - return Optional.ofNullable(getMappedForm().getType()) + default String getTypeName(PropertyConfig config, Mapping mapping) { + return Optional.ofNullable(config.getType()) .map(typeObj -> typeObj instanceof Class<?> clazz ? clazz.getName() : typeObj.toString()) .orElseGet(() -> mapping != null ? mapping.getTypeName(getType()) : null); } + /** + * @param mapping The mapping + * @return The type name + */ + default String getTypeName(Mapping mapping) { + return getTypeName(getMappedForm(), mapping); + } + + /** + * @return The type name + */ + default String getTypeName() { + return getTypeName(getHibernateOwner().getMappedForm()); + } + default HibernatePersistentEntity getHibernateOwner() { return (HibernatePersistentEntity) getOwner(); } diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java index 546d456762..3c992b8505 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java @@ -48,7 +48,7 @@ public class EnumTypeBinder { String enumType = pc.getEnumType(); Properties enumProperties = new Properties(); enumProperties.put(ENUM_CLASS_PROP, propertyType.getName()); - String typeName = property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName(ownerMapping) : null; + String typeName = property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName() : null; if (typeName != null) { simpleValue.setTypeName(typeName); } else { diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionType.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionType.java index 04ae10a0c8..9b972cc96a 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionType.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionType.java @@ -73,9 +73,7 @@ public abstract class CollectionType { } public String getTypeName(ToMany<?> property) { - GrailsHibernatePersistentEntity domainClass = (GrailsHibernatePersistentEntity) property.getOwner(); - Mapping mapping = domainClass.getMappedForm(); - return property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName(mapping) : null; + return property instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName() : null; } } diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionTypeSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionTypeSpec.groovy index 204f9b0fef..85dfcb97ec 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionTypeSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/collectionType/CollectionTypeSpec.groovy @@ -46,15 +46,10 @@ class CollectionTypeSpec extends HibernateGormDatastoreSpec { def "getTypeName should return type name from GrailsHibernatePersistentProperty"() { given: - def mapping = Mock(org.grails.orm.hibernate.cfg.Mapping) - // Use HibernateOneToManyProperty which implements both ToMany and GrailsHibernatePersistentProperty def hibernateProp = Mock(HibernateOneToManyProperty) - def domainClass = Mock(GrailsHibernatePersistentEntity) - hibernateProp.getOwner() >> domainClass - domainClass.getMappedForm() >> mapping - hibernateProp.getTypeName(mapping) >> "my.custom.Type" + hibernateProp.getTypeName() >> "my.custom.Type" expect: collectionType.getTypeName(hibernateProp) == "my.custom.Type"
