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.RecoverableException;
import org.hibernate.cfg.SecondPass; import org.hibernate.cfg.SecondPass;
import org.hibernate.cfg.SecondaryTableSecondPass; import org.hibernate.cfg.SecondaryTableSecondPass;
import org.hibernate.cfg.SetBasicValueTypeSecondPass;
import org.hibernate.cfg.UniqueConstraintHolder; import org.hibernate.cfg.UniqueConstraintHolder;
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition; import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
@ -1543,6 +1544,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
private ArrayList<IdGeneratorResolverSecondPass> idGeneratorResolverSecondPassList; private ArrayList<IdGeneratorResolverSecondPass> idGeneratorResolverSecondPassList;
private ArrayList<PkDrivenByDefaultMapsIdSecondPass> pkDrivenByDefaultMapsIdSecondPassList; private ArrayList<PkDrivenByDefaultMapsIdSecondPass> pkDrivenByDefaultMapsIdSecondPassList;
private ArrayList<SetBasicValueTypeSecondPass> setBasicValueTypeSecondPassList;
private ArrayList<CopyIdentifierComponentSecondPass> copyIdentifierComponentSecondPasList; private ArrayList<CopyIdentifierComponentSecondPass> copyIdentifierComponentSecondPasList;
private ArrayList<FkSecondPass> fkSecondPassList; private ArrayList<FkSecondPass> fkSecondPassList;
private ArrayList<CreateKeySecondPass> createKeySecondPasList; private ArrayList<CreateKeySecondPass> createKeySecondPasList;
@ -1565,6 +1567,9 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
else if ( secondPass instanceof PkDrivenByDefaultMapsIdSecondPass ) { else if ( secondPass instanceof PkDrivenByDefaultMapsIdSecondPass ) {
addPkDrivenByDefaultMapsIdSecondPass( (PkDrivenByDefaultMapsIdSecondPass) secondPass, onTopOfTheQueue ); addPkDrivenByDefaultMapsIdSecondPass( (PkDrivenByDefaultMapsIdSecondPass) secondPass, onTopOfTheQueue );
} }
else if ( secondPass instanceof SetBasicValueTypeSecondPass ) {
addSetBasicValueTypeSecondPass( (SetBasicValueTypeSecondPass) secondPass, onTopOfTheQueue );
}
else if ( secondPass instanceof CopyIdentifierComponentSecondPass ) { else if ( secondPass instanceof CopyIdentifierComponentSecondPass ) {
addCopyIdentifierComponentSecondPass( (CopyIdentifierComponentSecondPass) secondPass, onTopOfTheQueue ); 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) { private void addIdGeneratorResolverSecondPass(IdGeneratorResolverSecondPass secondPass, boolean onTopOfTheQueue) {
if ( idGeneratorResolverSecondPassList == null ) { if ( idGeneratorResolverSecondPassList == null ) {
idGeneratorResolverSecondPassList = new ArrayList<>(); idGeneratorResolverSecondPassList = new ArrayList<>();
@ -1675,6 +1687,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
processSecondPasses( idGeneratorResolverSecondPassList ); processSecondPasses( idGeneratorResolverSecondPassList );
processSecondPasses( implicitColumnNamingSecondPassList ); processSecondPasses( implicitColumnNamingSecondPassList );
processSecondPasses( pkDrivenByDefaultMapsIdSecondPassList ); processSecondPasses( pkDrivenByDefaultMapsIdSecondPassList );
processSecondPasses( setBasicValueTypeSecondPassList );
processCopyIdentifierSecondPassesInOrder(); processCopyIdentifierSecondPassesInOrder();

View File

@ -157,8 +157,7 @@ public class CopyIdentifierComponentSecondPass implements SecondPass {
SimpleValue value = new BasicValue( buildingContext, component.getTable() ); SimpleValue value = new BasicValue( buildingContext, component.getTable() );
property.setValue( value ); property.setValue( value );
final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue(); final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue();
value.setTypeName( referencedValue.getTypeName() ); value.copyTypeFrom( referencedValue );
value.setTypeParameters( referencedValue.getTypeParameters() );
final Iterator<Selectable> columns = referencedValue.getColumnIterator(); final Iterator<Selectable> columns = referencedValue.getColumnIterator();
if ( joinColumns[0].isNameDeferred() ) { if ( joinColumns[0].isNameDeferred() ) {

View File

@ -302,7 +302,7 @@ public class BasicValueBinder<T> implements JdbcTypeDescriptorIndicators {
break; break;
} }
case MAP_KEY: { case MAP_KEY: {
prepareMapKey( modelXProperty ); prepareMapKey( modelXProperty, modelPropertyTypeXClass );
break; break;
} }
case COLLECTION_ELEMENT: { case COLLECTION_ELEMENT: {
@ -329,11 +329,19 @@ public class BasicValueBinder<T> implements JdbcTypeDescriptorIndicators {
final String generator = collectionIdAnn.generator(); final String generator = collectionIdAnn.generator();
} }
private void prepareMapKey(XProperty mapAttribute) { private void prepareMapKey(
//noinspection rawtypes XProperty mapAttribute,
final Class implicitJavaType = buildingContext.getBootstrapContext() XClass modelPropertyTypeXClass) {
final XClass mapKeyClass;
if ( modelPropertyTypeXClass == null ) {
mapKeyClass = mapAttribute.getMapKey();
}
else {
mapKeyClass = modelPropertyTypeXClass;
}
final Class<?> implicitJavaType = buildingContext.getBootstrapContext()
.getReflectionManager() .getReflectionManager()
.toClass( mapAttribute.getMapKey() ); .toClass( mapKeyClass );
implicitJavaTypeAccess = typeConfiguration -> implicitJavaType; implicitJavaTypeAccess = typeConfiguration -> implicitJavaType;

View File

@ -191,7 +191,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeDescriptorIndicat
} }
final Selectable column = getColumn(); 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() ); log.debugf( "Skipping column re-registration: %s.%s", getTable().getName(), column.getText() );
return; return;
} }