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 9bea252646407011aa826f113fa2533654886bae Author: Walter Duque de Estrada <[email protected]> AuthorDate: Wed Feb 18 15:43:55 2026 -0600 Add sort and order convenience methods to HibernateToManyProperty and simplify CollectionSecondPassBinder --- .../domainbinding/hibernate/HibernateToManyProperty.java | 13 +++++++++++++ .../secondpass/CollectionSecondPassBinder.java | 15 ++++++--------- 2 files changed, 19 insertions(+), 9 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 cbdb72e4e9..317860cdbb 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 @@ -7,6 +7,7 @@ import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty; import org.grails.orm.hibernate.cfg.PropertyConfig; import org.hibernate.FetchMode; +import org.springframework.util.StringUtils; import java.util.Map; @@ -15,6 +16,18 @@ import java.util.Map; */ public interface HibernateToManyProperty extends PropertyWithMapping<PropertyConfig>, GrailsHibernatePersistentProperty { + default boolean hasSort() { + return StringUtils.hasText(getMappedForm().getSort()); + } + + default String getSort() { + return getMappedForm().getSort(); + } + + default String getOrder() { + return getMappedForm().getOrder(); + } + default boolean getIgnoreNotFound() { return getMappedForm().getIgnoreNotFound(); } 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 23c31a85fa..3feecc1a17 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 @@ -21,7 +21,6 @@ import org.hibernate.mapping.*; import org.hibernate.mapping.Collection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; import java.util.*; import java.util.Map; @@ -83,23 +82,21 @@ public class CollectionSecondPassBinder { + " -> " + collection.getCollectionTable().getName()); - PropertyConfig propConfig = property.getMappedForm(); - GrailsHibernatePersistentEntity referenced = property.getHibernateAssociatedEntity(); - if (StringUtils.hasText(propConfig.getSort())) { + if (property.hasSort()) { if (!property.isBidirectional() && (property instanceof HibernateOneToManyProperty)) { throw new DatastoreConfigurationException("Default sort for associations ["+property.getHibernateOwner().getName()+"->" + property.getName() + "] are not supported with unidirectional one to many relationships."); } if (referenced != null) { - GrailsHibernatePersistentProperty propertyToSortBy = (GrailsHibernatePersistentProperty) referenced.getPropertyByName(propConfig.getSort()); + GrailsHibernatePersistentProperty propertyToSortBy = (GrailsHibernatePersistentProperty) referenced.getPropertyByName(property.getSort()); String associatedClassName = referenced.getName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); if (associatedClass != null) { collection.setOrderBy(orderByClauseBuilder.buildOrderByClause(propertyToSortBy.getName(), associatedClass, collection.getRole(), - propConfig.getOrder() != null ? propConfig.getOrder() : "asc")); + property.getOrder() != null ? property.getOrder() : "asc")); } } } @@ -170,9 +167,9 @@ public class CollectionSecondPassBinder { } else { - if (propConfig.hasJoinKeyMapping()) { + if (property.getMappedForm().hasJoinKeyMapping()) { - String columnName = propConfig.getJoinTable().getKey().getName(); + String columnName = property.getMappedForm().getJoinTable().getKey().getName(); new SimpleValueColumnBinder().bindSimpleValue(key, "long", columnName, true); @@ -186,7 +183,7 @@ public class CollectionSecondPassBinder { collection.setKey(key); // get cache config - CacheConfig cacheConfig = propConfig.getCache(); + CacheConfig cacheConfig = property.getMappedForm().getCache(); if (cacheConfig != null) { collection.setCacheConcurrencyStrategy(cacheConfig.getUsage()); }
