From 26339598a54ea737f9050f5b612abd9f48078e1f Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 17 Jul 2020 10:23:44 +0100 Subject: [PATCH] Resolved issue with DependandValue resolution --- .../org/hibernate/mapping/BasicValue.java | 4 ++- .../org/hibernate/mapping/DependantValue.java | 25 ++++++++++++++++--- .../org/hibernate/mapping/Resolvable.java | 20 +++++++++++++++ .../internal/MappingModelCreationHelper.java | 7 ++++-- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/mapping/Resolvable.java diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java index 2ff51b284e..b682efcf68 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java @@ -50,7 +50,7 @@ import org.hibernate.type.spi.TypeConfiguration; * @author Steve Ebersole */ @SuppressWarnings({"unchecked", "rawtypes"}) -public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicators { +public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicators, Resolvable { private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class ); private final MetadataBuildingContext buildingContext; @@ -245,11 +245,13 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato return resolution; } + @Override public boolean resolve(MetadataBuildingContext buildingContext) { resolve(); return true; } + @Override public Resolution resolve() { if ( resolution != null ) { return resolution; diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/DependantValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/DependantValue.java index 61d448d000..9bc6ac5345 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/DependantValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/DependantValue.java @@ -17,7 +17,7 @@ import org.hibernate.type.Type; * * @author Gavin King */ -public class DependantValue extends SimpleValue { +public class DependantValue extends SimpleValue implements Resolvable { private KeyValue wrappedValue; private boolean nullable; private boolean updateable; @@ -31,12 +31,15 @@ public class DependantValue extends SimpleValue { return wrappedValue.getType(); } + @Override public void setTypeUsingReflection(String className, String propertyName) {} - + + @Override public Object accept(ValueVisitor visitor) { return visitor.accept(this); } + @Override public boolean isNullable() { return nullable; @@ -45,7 +48,8 @@ public class DependantValue extends SimpleValue { public void setNullable(boolean nullable) { this.nullable = nullable; } - + + @Override public boolean isUpdateable() { return updateable; } @@ -64,4 +68,19 @@ public class DependantValue extends SimpleValue { && isSame( wrappedValue, other.wrappedValue ); } + @Override + public boolean resolve(MetadataBuildingContext buildingContext) { + resolve(); + return true; + } + + @Override + public BasicValue.Resolution resolve() { + if ( wrappedValue instanceof BasicValue ) { + return ( (BasicValue) wrappedValue ).resolve(); + } + // not sure it is ever possible + throw new UnsupportedOperationException("Trying to resolve the wrapped value but it is non a BasicValue"); + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Resolvable.java b/hibernate-core/src/main/java/org/hibernate/mapping/Resolvable.java new file mode 100644 index 0000000000..06ce9b3221 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Resolvable.java @@ -0,0 +1,20 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.mapping; + +import org.hibernate.boot.spi.MetadataBuildingContext; + +/** + * @author Andrea Boriero + */ +public interface Resolvable { + + boolean resolve(MetadataBuildingContext buildingContext); + + BasicValue.Resolution resolve(); +} + 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 4c52f33737..41dc14ace6 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 @@ -36,12 +36,14 @@ import org.hibernate.internal.util.collections.CollectionHelper; 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.OneToMany; import org.hibernate.mapping.OneToOne; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; +import org.hibernate.mapping.Resolvable; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Table; import org.hibernate.mapping.ToOne; @@ -277,13 +279,14 @@ public class MappingModelCreationHelper { PropertyAccess propertyAccess, CascadeStyle cascadeStyle, MappingModelCreationProcess creationProcess) { - final BasicValue.Resolution resolution = ( (BasicValue) bootProperty.getValue() ).resolve(); + final Value value = bootProperty.getValue(); + final BasicValue.Resolution resolution = ( (Resolvable) value ).resolve(); final BasicValueConverter valueConverter = resolution.getValueConverter(); final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() { private final MutabilityPlan mutabilityPlan = resolution.getMutabilityPlan(); - private final boolean nullable = bootProperty.getValue().isNullable(); + private final boolean nullable = value.isNullable(); private final boolean insertable = bootProperty.isInsertable(); private final boolean updateable = bootProperty.isUpdateable(); private final boolean includeInOptimisticLocking = bootProperty.isOptimisticLocked();