HHH-13295 Always perform @MapsId's second pass after entity ID second passes

This commit is contained in:
Yoann Rodière 2021-10-08 16:30:12 +02:00 committed by Sanne Grinovero
parent 2396dfbb3d
commit 7906a27b6a
2 changed files with 15 additions and 16 deletions

View File

@ -62,7 +62,6 @@ import org.hibernate.cfg.CreateKeySecondPass;
import org.hibernate.cfg.FkSecondPass;
import org.hibernate.cfg.IdGeneratorResolverSecondPass;
import org.hibernate.cfg.JPAIndexHolder;
import org.hibernate.cfg.PkDrivenByDefaultMapsIdSecondPass;
import org.hibernate.cfg.PropertyData;
import org.hibernate.cfg.QuerySecondPass;
import org.hibernate.cfg.RecoverableException;
@ -1504,7 +1503,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
}
private ArrayList<IdGeneratorResolverSecondPass> idGeneratorResolverSecondPassList;
private ArrayList<PkDrivenByDefaultMapsIdSecondPass> pkDrivenByDefaultMapsIdSecondPassList;
private ArrayList<SetSimpleValueTypeSecondPass> setSimpleValueTypeSecondPassList;
private ArrayList<CopyIdentifierComponentSecondPass> copyIdentifierComponentSecondPasList;
private ArrayList<FkSecondPass> fkSecondPassList;
@ -1525,9 +1523,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
if ( secondPass instanceof IdGeneratorResolverSecondPass ) {
addIdGeneratorResolverSecondPass( (IdGeneratorResolverSecondPass) secondPass, onTopOfTheQueue );
}
else if ( secondPass instanceof PkDrivenByDefaultMapsIdSecondPass ) {
addPkDrivenByDefaultMapsIdSecondPass( (PkDrivenByDefaultMapsIdSecondPass) secondPass, onTopOfTheQueue );
}
else if ( secondPass instanceof SetSimpleValueTypeSecondPass ) {
addSetSimpleValueTypeSecondPass( (SetSimpleValueTypeSecondPass) secondPass, onTopOfTheQueue );
}
@ -1558,15 +1553,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
}
}
private void addPkDrivenByDefaultMapsIdSecondPass(
PkDrivenByDefaultMapsIdSecondPass secondPass,
boolean onTopOfTheQueue) {
if ( pkDrivenByDefaultMapsIdSecondPassList == null ) {
pkDrivenByDefaultMapsIdSecondPassList = new ArrayList<>();
}
addSecondPass( secondPass, pkDrivenByDefaultMapsIdSecondPassList, onTopOfTheQueue );
}
private <T extends SecondPass> void addSecondPass(T secondPass, ArrayList<T> secondPassList, boolean onTopOfTheQueue) {
if ( onTopOfTheQueue ) {
secondPassList.add( 0, secondPass );
@ -1647,7 +1633,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
try {
processSecondPasses( idGeneratorResolverSecondPassList );
processSecondPasses( implicitColumnNamingSecondPassList );
processSecondPasses( pkDrivenByDefaultMapsIdSecondPassList );
processSecondPasses( setSimpleValueTypeSecondPassList );
processCopyIdentifierSecondPassesInOrder();

View File

@ -16,17 +16,31 @@ import org.hibernate.mapping.SimpleValue;
/**
* @author Emmanuel Bernard
*/
public class PkDrivenByDefaultMapsIdSecondPass implements SecondPass {
public class PkDrivenByDefaultMapsIdSecondPass extends FkSecondPass {
private final String referencedEntityName;
private final Ejb3JoinColumn[] columns;
private final SimpleValue value;
public PkDrivenByDefaultMapsIdSecondPass(String referencedEntityName, Ejb3JoinColumn[] columns, SimpleValue value) {
super( value, columns );
this.referencedEntityName = referencedEntityName;
this.columns = columns;
this.value = value;
}
@Override
public String getReferencedEntityName() {
return referencedEntityName;
}
@Override
public boolean isInPrimaryKey() {
// @MapsId is not itself in the primary key,
// so it's safe to simply process it after all the primary keys have been processed.
return true;
}
@Override
public void doSecondPass(Map persistentClasses) throws MappingException {
PersistentClass referencedEntity = (PersistentClass) persistentClasses.get( referencedEntityName );
if ( referencedEntity == null ) {