From 60fc0c018abbc33e235ca2d71a4ae865fb521f4f Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Mon, 2 Jan 2023 17:15:05 +0100 Subject: [PATCH] HHH-15866 Handle DependantValue when building embedded attr mapping --- .../mapping/internal/EmbeddableMappingTypeImpl.java | 9 ++++++++- .../mapping/internal/MappingModelCreationHelper.java | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java index 600c7a64b4..17abc38da2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java @@ -29,6 +29,7 @@ import org.hibernate.mapping.Any; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Column; import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; import org.hibernate.mapping.IndexedConsumer; import org.hibernate.mapping.Property; import org.hibernate.mapping.Selectable; @@ -92,6 +93,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme null, null, null, + null, insertability, updateability, embeddedPartBuilder, @@ -105,6 +107,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme String rootTableExpression, String[] rootTableKeyColumnNames, Property componentProperty, + DependantValue dependantValue, boolean[] insertability, boolean[] updateability, Function embeddedPartBuilder, @@ -130,6 +133,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme compositeType, rootTableExpression, rootTableKeyColumnNames, + dependantValue, insertability, updateability, creationProcess @@ -294,6 +298,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme CompositeType compositeType, String rootTableExpression, String[] rootTableKeyColumnNames, + DependantValue dependantValue, boolean[] insertability, boolean[] updateability, MappingModelCreationProcess creationProcess) { @@ -344,7 +349,9 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme final Value value = bootPropertyDescriptor.getValue(); if ( subtype instanceof BasicType ) { final BasicValue basicValue = (BasicValue) value; - final Selectable selectable = basicValue.getColumn(); + final Selectable selectable = dependantValue != null ? + dependantValue.getColumns().get( columnPosition ) : + basicValue.getColumn(); final String containingTableExpression; final String columnExpression; if ( rootTableKeyColumnNames == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 098d0c587c..0f342c97da 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -31,6 +31,7 @@ import org.hibernate.mapping.Any; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.ManyToOne; @@ -134,6 +135,7 @@ public class MappingModelCreationHelper { rootTableName, rootTableKeyColumnNames, bootProperty, + null, component.getColumnInsertability(), component.getColumnUpdateability(), embeddable -> new EmbeddedIdentifierMappingImpl( @@ -266,13 +268,21 @@ public class MappingModelCreationHelper { creationProcess ); - final Component component = (Component) bootProperty.getValue(); + Value componentValue = bootProperty.getValue(); + DependantValue dependantValue = null; + if ( componentValue instanceof DependantValue ) { + dependantValue = ( (DependantValue) componentValue ); + componentValue = dependantValue.getWrappedValue(); + } + + final Component component = (Component) componentValue; final EmbeddableMappingTypeImpl embeddableMappingType = EmbeddableMappingTypeImpl.from( component, attrType, tableExpression, rootTableKeyColumnNames, bootProperty, + dependantValue, component.getColumnInsertability(), component.getColumnUpdateability(), attributeMappingType -> {