diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index 09a81b3a67..8d1f519f3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -76,6 +76,7 @@ import org.hibernate.cfg.QuerySecondPass; import org.hibernate.cfg.RecoverableException; import org.hibernate.cfg.SecondPass; import org.hibernate.cfg.SecondaryTableSecondPass; +import org.hibernate.cfg.SetBasicValueTypeSecondPass; import org.hibernate.cfg.UniqueConstraintHolder; import org.hibernate.cfg.annotations.NamedEntityGraphDefinition; import org.hibernate.dialect.Dialect; @@ -1543,6 +1544,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector private ArrayList idGeneratorResolverSecondPassList; private ArrayList pkDrivenByDefaultMapsIdSecondPassList; + private ArrayList setBasicValueTypeSecondPassList; private ArrayList copyIdentifierComponentSecondPasList; private ArrayList fkSecondPassList; private ArrayList createKeySecondPasList; @@ -1565,6 +1567,9 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector else if ( secondPass instanceof PkDrivenByDefaultMapsIdSecondPass ) { addPkDrivenByDefaultMapsIdSecondPass( (PkDrivenByDefaultMapsIdSecondPass) secondPass, onTopOfTheQueue ); } + else if ( secondPass instanceof SetBasicValueTypeSecondPass ) { + addSetBasicValueTypeSecondPass( (SetBasicValueTypeSecondPass) secondPass, onTopOfTheQueue ); + } else if ( secondPass instanceof CopyIdentifierComponentSecondPass ) { addCopyIdentifierComponentSecondPass( (CopyIdentifierComponentSecondPass) secondPass, onTopOfTheQueue ); } @@ -1610,6 +1615,13 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector } } + private void addSetBasicValueTypeSecondPass(SetBasicValueTypeSecondPass secondPass, boolean onTopOfTheQueue) { + if ( setBasicValueTypeSecondPassList == null ) { + setBasicValueTypeSecondPassList = new ArrayList<>(); + } + addSecondPass( secondPass, setBasicValueTypeSecondPassList, onTopOfTheQueue ); + } + private void addIdGeneratorResolverSecondPass(IdGeneratorResolverSecondPass secondPass, boolean onTopOfTheQueue) { if ( idGeneratorResolverSecondPassList == null ) { idGeneratorResolverSecondPassList = new ArrayList<>(); @@ -1675,6 +1687,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector processSecondPasses( idGeneratorResolverSecondPassList ); processSecondPasses( implicitColumnNamingSecondPassList ); processSecondPasses( pkDrivenByDefaultMapsIdSecondPassList ); + processSecondPasses( setBasicValueTypeSecondPassList ); processCopyIdentifierSecondPassesInOrder(); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java index 9453b888e2..d16036aa48 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java @@ -157,8 +157,7 @@ public class CopyIdentifierComponentSecondPass implements SecondPass { SimpleValue value = new BasicValue( buildingContext, component.getTable() ); property.setValue( value ); final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue(); - value.setTypeName( referencedValue.getTypeName() ); - value.setTypeParameters( referencedValue.getTypeParameters() ); + value.copyTypeFrom( referencedValue ); final Iterator columns = referencedValue.getColumnIterator(); if ( joinColumns[0].isNameDeferred() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/BasicValueBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/BasicValueBinder.java index 33f7567fcd..f947b60403 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/BasicValueBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/BasicValueBinder.java @@ -302,7 +302,7 @@ public class BasicValueBinder implements JdbcTypeDescriptorIndicators { break; } case MAP_KEY: { - prepareMapKey( modelXProperty ); + prepareMapKey( modelXProperty, modelPropertyTypeXClass ); break; } case COLLECTION_ELEMENT: { @@ -329,11 +329,19 @@ public class BasicValueBinder implements JdbcTypeDescriptorIndicators { final String generator = collectionIdAnn.generator(); } - private void prepareMapKey(XProperty mapAttribute) { - //noinspection rawtypes - final Class implicitJavaType = buildingContext.getBootstrapContext() + private void prepareMapKey( + XProperty mapAttribute, + XClass modelPropertyTypeXClass) { + final XClass mapKeyClass; + if ( modelPropertyTypeXClass == null ) { + mapKeyClass = mapAttribute.getMapKey(); + } + else { + mapKeyClass = modelPropertyTypeXClass; + } + final Class implicitJavaType = buildingContext.getBootstrapContext() .getReflectionManager() - .toClass( mapAttribute.getMapKey() ); + .toClass( mapKeyClass ); implicitJavaTypeAccess = typeConfiguration -> implicitJavaType; 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 755f1f7838..f5f5ba86d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java @@ -191,7 +191,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeDescriptorIndicat } final Selectable column = getColumn(); - if ( column == incomingColumn ) { + if ( column == incomingColumn || column.getText().equals( incomingColumn.getText() ) ) { log.debugf( "Skipping column re-registration: %s.%s", getTable().getName(), column.getText() ); return; }