HHH-15866 Handle DependantValue when building embedded attr mapping

This commit is contained in:
Marco Belladelli 2023-01-02 17:15:05 +01:00 committed by Christian Beikov
parent 461383c8d1
commit 60fc0c018a
2 changed files with 19 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import org.hibernate.mapping.Any;
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.DependantValue;
import org.hibernate.mapping.IndexedConsumer; import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
@ -92,6 +93,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
null, null,
null, null,
null, null,
null,
insertability, insertability,
updateability, updateability,
embeddedPartBuilder, embeddedPartBuilder,
@ -105,6 +107,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
String rootTableExpression, String rootTableExpression,
String[] rootTableKeyColumnNames, String[] rootTableKeyColumnNames,
Property componentProperty, Property componentProperty,
DependantValue dependantValue,
boolean[] insertability, boolean[] insertability,
boolean[] updateability, boolean[] updateability,
Function<EmbeddableMappingType,EmbeddableValuedModelPart> embeddedPartBuilder, Function<EmbeddableMappingType,EmbeddableValuedModelPart> embeddedPartBuilder,
@ -130,6 +133,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
compositeType, compositeType,
rootTableExpression, rootTableExpression,
rootTableKeyColumnNames, rootTableKeyColumnNames,
dependantValue,
insertability, insertability,
updateability, updateability,
creationProcess creationProcess
@ -294,6 +298,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
CompositeType compositeType, CompositeType compositeType,
String rootTableExpression, String rootTableExpression,
String[] rootTableKeyColumnNames, String[] rootTableKeyColumnNames,
DependantValue dependantValue,
boolean[] insertability, boolean[] insertability,
boolean[] updateability, boolean[] updateability,
MappingModelCreationProcess creationProcess) { MappingModelCreationProcess creationProcess) {
@ -344,7 +349,9 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
final Value value = bootPropertyDescriptor.getValue(); final Value value = bootPropertyDescriptor.getValue();
if ( subtype instanceof BasicType ) { if ( subtype instanceof BasicType ) {
final BasicValue basicValue = (BasicValue) value; 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 containingTableExpression;
final String columnExpression; final String columnExpression;
if ( rootTableKeyColumnNames == null ) { if ( rootTableKeyColumnNames == null ) {

View File

@ -31,6 +31,7 @@ import org.hibernate.mapping.Any;
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.DependantValue;
import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.IndexedCollection;
import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.ManyToOne; import org.hibernate.mapping.ManyToOne;
@ -134,6 +135,7 @@ public class MappingModelCreationHelper {
rootTableName, rootTableName,
rootTableKeyColumnNames, rootTableKeyColumnNames,
bootProperty, bootProperty,
null,
component.getColumnInsertability(), component.getColumnInsertability(),
component.getColumnUpdateability(), component.getColumnUpdateability(),
embeddable -> new EmbeddedIdentifierMappingImpl( embeddable -> new EmbeddedIdentifierMappingImpl(
@ -266,13 +268,21 @@ public class MappingModelCreationHelper {
creationProcess 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( final EmbeddableMappingTypeImpl embeddableMappingType = EmbeddableMappingTypeImpl.from(
component, component,
attrType, attrType,
tableExpression, tableExpression,
rootTableKeyColumnNames, rootTableKeyColumnNames,
bootProperty, bootProperty,
dependantValue,
component.getColumnInsertability(), component.getColumnInsertability(),
component.getColumnUpdateability(), component.getColumnUpdateability(),
attributeMappingType -> { attributeMappingType -> {