You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/02/06 19:09:50 UTC
(grails-core) 03/19: Fixed tests
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 70cb6ac59b4f59d2ef32be8cf6ea71cb40c2238d
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Mon Feb 2 13:48:11 2026 -0600
Fixed tests
---
.../orm/hibernate/cfg/GrailsDomainBinder.java | 85 ++++++++++++----------
.../cfg/GrailsHibernatePersistentEntity.java | 23 +++++-
.../hibernate/cfg/HibernatePersistentEntity.java | 6 --
3 files changed, 64 insertions(+), 50 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 043f99e247..02167b324c 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,18 +1492,8 @@ public class GrailsDomainBinder
Mapping gormMapping = domainClass.getMappedForm();
Table table = persistentClass.getTable();
table.setComment(gormMapping.getComment());
- 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) {
+
+ for (GrailsHibernatePersistentProperty currentGrailsProp : domainClass.getPersistentPropertiesToBind()) {
bindProperty(persistentClass, mappings, sessionFactoryBeanName, currentGrailsProp, table, gormMapping);
}
@@ -1513,7 +1503,7 @@ public class GrailsDomainBinder
private void bindProperty(PersistentClass persistentClass
, @NonNull InFlightMetadataCollector mappings
, String sessionFactoryBeanName
- , @Nonnull PersistentProperty<?> currentGrailsProp
+ , @Nonnull GrailsHibernatePersistentProperty currentGrailsProp
, Table table
, Mapping gormMapping) {
if (LOG.isDebugEnabled()) {
@@ -1527,21 +1517,14 @@ 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 instanceof GrailsHibernatePersistentProperty ghpp ? ghpp.getTypeName(gormMapping) : null;
+ String typeName = currentGrailsProp.getTypeName(gormMapping);
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
@@ -1553,23 +1536,13 @@ 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() +
@@ -1577,32 +1550,64 @@ 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 SimpleValue");
+ 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);
}
- 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 50c0a4b4f5..b0db1c066a 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,10 +1,12 @@
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;
/**
@@ -33,10 +35,23 @@ public interface GrailsHibernatePersistentEntity extends PersistentEntity {
boolean isAbstract();
-
- @SuppressWarnings("unchecked")
- default List<GrailsHibernatePersistentProperty> getHibernatePersistentProperties() {
- return (List) getPersistentProperties();
+ /**
+ * @return The properties that should be bound to the Hibernate meta model
+ */
+ default List<GrailsHibernatePersistentProperty> getPersistentPropertiesToBind() {
+ List<PersistentProperty> properties = getPersistentProperties();
+ if (properties == null) {
+ return java.util.Collections.emptyList();
+ }
+ return properties.stream()
+ .filter(Objects::nonNull)
+ .filter(p -> p.getMappedForm() != null)
+ .filter(p -> !p.isIdentityProperty())
+ .filter(p -> !p.isCompositeIdProperty())
+ .filter(p -> !GormProperties.VERSION.equals(p.getName()))
+ .filter(p -> !p.isInherited())
+ .map(p -> (GrailsHibernatePersistentProperty) p)
+ .toList();
}
@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 26be8f29dc..c319757d71 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,11 +90,5 @@ public class HibernatePersistentEntity extends AbstractPersistentEntity<Mapping>
return (GrailsHibernatePersistentProperty) version;
}
- @Override
- @SuppressWarnings("unchecked")
- public java.util.List<GrailsHibernatePersistentProperty> getHibernatePersistentProperties() {
- return (java.util.List) persistentProperties;
- }
-
}