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 875d23b941811c06c326d47d2e12fdab44319f51
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Sun Feb 15 13:15:22 2026 -0600

    Refactor bindRoot to use entity.isTablePerHierarchy() and cleanup 
polymorphic logic
    
    - Add isTablePerHierarchy() default method to 
GrailsHibernatePersistentEntity.
    - Update GrailsDomainBinder.bindRoot to use entity.isTablePerHierarchy() 
and remove redundant tablePerSubclass variable.
    - Remove deprecated setPolymorphic calls and redundant Table argument in 
bindDiscriminatorProperty.
---
 .../org/grails/orm/hibernate/cfg/GrailsDomainBinder.java      | 11 ++++-------
 .../orm/hibernate/cfg/GrailsHibernatePersistentEntity.java    |  5 +++++
 2 files changed, 9 insertions(+), 7 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 8ee1eb3815..e10a69e3a8 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
@@ -279,11 +279,8 @@ public class GrailsDomainBinder
         RootClass root = bindRootPersistentClassCommonValues(entity, children, 
mappings, sessionFactoryBeanName, identityBinder, versionBinder, 
grailsPropertyBinder, classBinder, propertyFromValueCreator);
         Mapping m = entity.getMappedForm();
         final Mapping finalMapping = m;
-        boolean tablePerSubclass = !m.getTablePerHierarchy();
-        if (!children.isEmpty() && !tablePerSubclass) {
-            // if the root class has children create a discriminator property
-
-            bindDiscriminatorProperty(root.getTable(), root, m);
+        if (!children.isEmpty() && entity.isTablePerHierarchy()) {
+            bindDiscriminatorProperty(root, m);
         }
         // bind the sub classes
         children.forEach(sub -> bindSubClass(sub, root, mappings, 
sessionFactoryBeanName, finalMapping,mappingCacheHolder, 
defaultColumnNameFetcher, columnNameForPropertyAndPathFetcher, 
grailsPropertyBinder, classBinder, propertyFromValueCreator, 
multiTenantFilterBinder, joinedSubClassBinder, unionSubclassBinder, 
singleTableSubclassBinder));
@@ -374,11 +371,11 @@ public class GrailsDomainBinder
      * Creates and binds the discriminator property used in 
table-per-hierarchy inheritance to
      * discriminate between sub class instances
      *
-     * @param table       The table to bind onto
      * @param entity      The root class entity
      * @param someMapping The mappings instance
      */
-    private void bindDiscriminatorProperty(Table table, RootClass entity, 
Mapping someMapping) {
+    private void bindDiscriminatorProperty(RootClass entity, Mapping 
someMapping) {
+        Table table = entity.getTable();
         SimpleValue d = new BasicValue(metadataBuildingContext, table);
         entity.setDiscriminator(d);
         DiscriminatorConfig discriminatorConfig = 
someMapping.getDiscriminator();
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 f055ebc521..d27f5aa8c0 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
@@ -36,6 +36,11 @@ package org.grails.orm.hibernate.cfg;
          return getHibernateRootEntity().getMappedForm();
      }
  
+     default boolean isTablePerHierarchy() {
+         Mapping mapping = getMappedForm();
+         return mapping == null || mapping.getTablePerHierarchy();
+     }
+
      default boolean isTablePerHierarchySubclass() {
          Mapping rootMapping = getRootMapping();
          return !this.isRoot() && (rootMapping == null || 
rootMapping.getTablePerHierarchy());

Reply via email to