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 c8e19e54fe0f706005ac543947c10fa927c4dc3a Author: Walter Duque de Estrada <[email protected]> AuthorDate: Mon Feb 2 13:37:05 2026 -0600 Revert "Refactor bindProperty and implement fluent property filtering" This reverts commit f1725f3d3b99df90efab53268512547d0f13661d. --- .../orm/hibernate/cfg/GrailsDomainBinder.java | 85 ++++++++++------------ .../cfg/GrailsHibernatePersistentEntity.java | 21 +----- .../hibernate/cfg/HibernatePersistentEntity.java | 6 ++ 3 files changed, 50 insertions(+), 62 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 02167b324c..043f99e247 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 @@ -1492,8 +1492,18 @@ public class GrailsDomainBinder Mapping gormMapping = domainClass.getMappedForm(); Table table = persistentClass.getTable(); table.setComment(gormMapping.getComment()); - - for (GrailsHibernatePersistentProperty currentGrailsProp : domainClass.getPersistentPropertiesToBind()) { + final List<PersistentProperty> persistentProperties = domainClass.getPersistentProperties() + .stream() + .filter(Objects::nonNull) + .filter(persistentProperty -> persistentProperty.getMappedForm() != null) + .filter(persistentProperty -> !persistentProperty.isCompositeIdProperty()) + .filter(persistentProperty -> !persistentProperty.isIdentityProperty()) + .filter(persistentProperty -> !persistentProperty.getName().equals(GormProperties.VERSION) ) + .filter(persistentProperty -> !persistentProperty.isInherited()) + .toList(); + + + for (PersistentProperty<?> currentGrailsProp : persistentProperties) { bindProperty(persistentClass, mappings, sessionFactoryBeanName, currentGrailsProp, table, gormMapping); } @@ -1503,7 +1513,7 @@ public class GrailsDomainBinder private void bindProperty(PersistentClass persistentClass , @NonNull InFlightMetadataCollector mappings , String sessionFactoryBeanName - , @Nonnull GrailsHibernatePersistentProperty currentGrailsProp + , @Nonnull PersistentProperty<?> currentGrailsProp , Table table , Mapping gormMapping) { if (LOG.isDebugEnabled()) { @@ -1517,14 +1527,21 @@ public class GrailsDomainBinder Class<?> userType = getUserType(currentGrailsProp); - // 1. Create Value if (userType != null && !UserCollectionType.class.isAssignableFrom(userType)) { + if (LOG.isDebugEnabled()) { + LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue"); + } value = new BasicValue(metadataBuildingContext, table); + // set type + new SimpleValueBinder(namingStrategy).bindSimpleValue(currentGrailsProp, null, (SimpleValue) value, EMPTY_PATH); } else if (collectionType != null) { - String typeName = currentGrailsProp.getTypeName(gormMapping); + String typeName = currentGrailsProp instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName(gormMapping) : null; if ("serializable".equals(typeName)) { value = new BasicValue(metadataBuildingContext, table); + boolean nullable = currentGrailsProp.isNullable(); + String columnName = new ColumnNameForPropertyAndPathFetcher(namingStrategy).getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null); + new SimpleValueColumnBinder().bindSimpleValue((SimpleValue) value, typeName, columnName, nullable); } else { // create collection @@ -1536,13 +1553,23 @@ public class GrailsDomainBinder } else if (currentGrailsProp.getType().isEnum()) { value = new BasicValue(metadataBuildingContext, table); + String columnName = new ColumnNameForPropertyAndPathFetcher(namingStrategy).getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null); + enumTypeBinder.bindEnumType(currentGrailsProp, currentGrailsProp.getType(), (SimpleValue) value, columnName); } else if(currentGrailsProp instanceof Association) { Association association = (Association) currentGrailsProp; if (currentGrailsProp instanceof org.grails.datastore.mapping.model.types.ManyToOne) { + if (LOG.isDebugEnabled()) + LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as ManyToOne"); + value = new ManyToOne(metadataBuildingContext, table); + new ManyToOneBinder(namingStrategy).bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, EMPTY_PATH); } else if (currentGrailsProp instanceof org.grails.datastore.mapping.model.types.OneToOne && userType == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as OneToOne"); + } + final boolean isHasOne = association.isHasOne(); if (isHasOne && !association.isBidirectional()) { throw new MappingException("hasOne property [" + currentGrailsProp.getOwner().getName() + @@ -1550,64 +1577,32 @@ public class GrailsDomainBinder } else if (((Association) currentGrailsProp).canBindOneToOneWithSingleColumnAndForeignKey()) { value = new OneToOne(metadataBuildingContext, table, persistentClass); + new OneToOneBinder(namingStrategy).bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne) currentGrailsProp, (OneToOne) value, EMPTY_PATH); } else { if (isHasOne && association.isBidirectional()) { value = new OneToOne(metadataBuildingContext, table, persistentClass); + new OneToOneBinder(namingStrategy).bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne) currentGrailsProp, (OneToOne) value, EMPTY_PATH); } else { value = new ManyToOne(metadataBuildingContext, table); + new ManyToOneBinder(namingStrategy).bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, EMPTY_PATH); } } } else if (currentGrailsProp instanceof Embedded) { value = new Component(metadataBuildingContext, persistentClass); + componentPropertyBinder.bindComponent((Component) value, (Embedded) currentGrailsProp, true, mappings, sessionFactoryBeanName); } } // work out what type of relationship it is and bind value else { - value = new BasicValue(metadataBuildingContext, table); - } - - // 2. Give the value to the binder - if (value instanceof Component component && currentGrailsProp instanceof Embedded embedded) { - componentPropertyBinder.bindComponent(component, embedded, true, mappings, sessionFactoryBeanName); - } - else if (value instanceof OneToOne oneToOne && currentGrailsProp instanceof org.grails.datastore.mapping.model.types.OneToOne oneToOneProp) { if (LOG.isDebugEnabled()) { - LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as OneToOne"); - } - new OneToOneBinder(namingStrategy).bindOneToOne(oneToOneProp, oneToOne, EMPTY_PATH); - } - else if (value instanceof ManyToOne manyToOne && currentGrailsProp instanceof Association association) { - if (LOG.isDebugEnabled()) { - LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as ManyToOne"); - } - new ManyToOneBinder(namingStrategy).bindManyToOne(association, manyToOne, EMPTY_PATH); - } - else if (value instanceof SimpleValue simpleValue) { - if (userType != null && !UserCollectionType.class.isAssignableFrom(userType)) { - if (LOG.isDebugEnabled()) { - LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue"); - } - new SimpleValueBinder(namingStrategy).bindSimpleValue(currentGrailsProp, null, simpleValue, EMPTY_PATH); - } - else if (currentGrailsProp.getType().isEnum()) { - 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); - boolean nullable = currentGrailsProp.isNullable(); - String columnName = new ColumnNameForPropertyAndPathFetcher(namingStrategy).getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null); - new SimpleValueColumnBinder().bindSimpleValue(simpleValue, typeName, columnName, nullable); - } - else { - if (LOG.isDebugEnabled()) { - LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue"); - } - new SimpleValueBinder(namingStrategy).bindSimpleValue(currentGrailsProp, null, simpleValue, EMPTY_PATH); + LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue"); } + value = new BasicValue(metadataBuildingContext, table); + // set type + new SimpleValueBinder(namingStrategy).bindSimpleValue(currentGrailsProp, null, (SimpleValue) value, EMPTY_PATH); } if (value != null) { diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java index 08905c1a2b..50c0a4b4f5 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java @@ -1,12 +1,10 @@ package org.grails.orm.hibernate.cfg; import java.util.List; -import java.util.Objects; import java.util.Optional; import org.grails.datastore.mapping.model.PersistentEntity; import org.grails.datastore.mapping.model.PersistentProperty; -import org.grails.datastore.mapping.model.config.GormProperties; import org.grails.orm.hibernate.cfg.domainbinding.ConfigureDerivedPropertiesConsumer; /** @@ -35,21 +33,10 @@ public interface GrailsHibernatePersistentEntity extends PersistentEntity { boolean isAbstract(); - /** - * @return The properties that should be bound to the Hibernate meta model - */ - default List<GrailsHibernatePersistentProperty> getPersistentPropertiesToBind() { - return Optional.ofNullable(getPersistentProperties()) - .stream() - .flatMap(java.util.Collection::stream) - .filter(GrailsHibernatePersistentProperty.class::isInstance) - .map(GrailsHibernatePersistentProperty.class::cast) - .filter(p -> p.getMappedForm() != null) - .filter(p -> !p.isIdentityProperty()) - .filter(p -> !p.isCompositeIdProperty()) - .filter(p -> !GormProperties.VERSION.equals(p.getName())) - .filter(p -> !p.isInherited()) - .toList(); + + @SuppressWarnings("unchecked") + default List<GrailsHibernatePersistentProperty> getHibernatePersistentProperties() { + return (List) getPersistentProperties(); } @Override diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernatePersistentEntity.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernatePersistentEntity.java index c319757d71..26be8f29dc 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernatePersistentEntity.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernatePersistentEntity.java @@ -90,5 +90,11 @@ public class HibernatePersistentEntity extends AbstractPersistentEntity<Mapping> return (GrailsHibernatePersistentProperty) version; } + @Override + @SuppressWarnings("unchecked") + public java.util.List<GrailsHibernatePersistentProperty> getHibernatePersistentProperties() { + return (java.util.List) persistentProperties; + } + }
