Handle basic value type bindings before the copy identifier component second pass like in Hibernate 5 to avoid issues with missing types

This commit is contained in:
Christian Beikov 2021-05-05 11:59:28 +02:00
parent 9bba88b10e
commit 8e26756cce
4 changed files with 28 additions and 8 deletions

View File

@ -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<IdGeneratorResolverSecondPass> idGeneratorResolverSecondPassList;
private ArrayList<PkDrivenByDefaultMapsIdSecondPass> pkDrivenByDefaultMapsIdSecondPassList;
private ArrayList<SetBasicValueTypeSecondPass> setBasicValueTypeSecondPassList;
private ArrayList<CopyIdentifierComponentSecondPass> copyIdentifierComponentSecondPasList;
private ArrayList<FkSecondPass> fkSecondPassList;
private ArrayList<CreateKeySecondPass> 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();

View File

@ -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<Selectable> columns = referencedValue.getColumnIterator();
if ( joinColumns[0].isNameDeferred() ) {

View File

@ -302,7 +302,7 @@ public class BasicValueBinder<T> implements JdbcTypeDescriptorIndicators {
break;
}
case MAP_KEY: {
prepareMapKey( modelXProperty );
prepareMapKey( modelXProperty, modelPropertyTypeXClass );
break;
}
case COLLECTION_ELEMENT: {
@ -329,11 +329,19 @@ public class BasicValueBinder<T> 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;

View File

@ -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;
}