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 467555a591586bc6a6d76b7bee56d87b777725a5 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Wed Feb 18 19:03:39 2026 -0600 Refactor getTypeName in GrailsHibernatePersistentProperty to support explicit types and simplify binders --- .../cfg/GrailsHibernatePersistentProperty.java | 22 ++++++++++++++++++++-- .../cfg/domainbinding/binder/EnumTypeBinder.java | 2 +- .../secondpass/CollectionWithJoinTableBinder.java | 7 +------ .../secondpass/MapSecondPassBinder.java | 15 +++++---------- 4 files changed, 27 insertions(+), 19 deletions(-) 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 7e5c327112..9e9cf4b1b8 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 @@ -59,7 +59,15 @@ public interface GrailsHibernatePersistentProperty extends PersistentProperty<Pr * @return The type name */ default String getTypeName() { - return getTypeName(getMappedForm(), getHibernateOwner().getMappedForm()); + return getTypeName(getType()); + } + + /** + * @param propertyType The property type + * @return The type name + */ + default String getTypeName(Class<?> propertyType) { + return getTypeName(propertyType, getMappedForm(), getHibernateOwner().getMappedForm()); } /** @@ -68,13 +76,23 @@ public interface GrailsHibernatePersistentProperty extends PersistentProperty<Pr * @return The type name */ default String getTypeName(PropertyConfig config, Mapping mapping) { + return getTypeName(getType(), config, mapping); + } + + /** + * @param propertyType The property type + * @param config The property config + * @param mapping The mapping + * @return The type name + */ + default String getTypeName(Class<?> propertyType, PropertyConfig config, Mapping mapping) { if (this instanceof Association) { return null; } return Optional.ofNullable(config) .map(PropertyConfig::getType) .map(typeObj -> typeObj instanceof Class<?> clazz ? clazz.getName() : typeObj.toString()) - .orElseGet(() -> mapping != null ? mapping.getTypeName(getType()) : null); + .orElseGet(() -> mapping != null ? mapping.getTypeName(propertyType) : null); } default GrailsHibernatePersistentEntity getHibernateOwner() { 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 2106474eb0..7e40b31f92 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 @@ -60,7 +60,7 @@ public class EnumTypeBinder { String enumType = pc.getEnumType(); Properties enumProperties = new Properties(); enumProperties.put(ENUM_CLASS_PROP, propertyType.getName()); - String typeName = property.getTypeName(); + String typeName = property.getTypeName(propertyType); if (typeName != null) { simpleValue.setTypeName(typeName); } else { 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 ea8ca64583..4d4faec043 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 @@ -88,12 +88,7 @@ public class CollectionWithJoinTableBinder { } else { - Mapping mapping = null; - GrailsHibernatePersistentEntity domainClass = property.getHibernateOwner(); - if (domainClass != null) { - mapping = domainClass.getMappedForm(); - } - String typeName = property.getTypeName(); + String typeName = property.getTypeName(referencedType); if (typeName == null) { Type type = mappings.getTypeConfiguration().getBasicTypeRegistry().getRegisteredType(className); if (type != null) { 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 1fe67ab891..2acecfff91 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,18 +66,13 @@ public class MapSecondPassBinder { SimpleValue elt = new BasicValue(metadataBuildingContext, map.getCollectionTable()); map.setElement(elt); - Mapping mapping = null; - GrailsHibernatePersistentEntity domainClass = (GrailsHibernatePersistentEntity) property.getOwner(); - if (domainClass != null) { - mapping = domainClass.getMappedForm(); + String typeName = null; + if (property instanceof Basic basic) { + typeName = property.getTypeName(basic.getComponentType()); } - String typeName = property.getTypeName(); - if (typeName == null ) { - if(property instanceof Basic) { - Basic basic = (Basic) property; - typeName = basic.getComponentType().getName(); - } + if (typeName == null) { + typeName = property.getTypeName(); } if(typeName == null || typeName.equals(Object.class.getName())) { typeName = StandardBasicTypes.STRING.getName();
