Skip to content

Commit ccd58ee

Browse files
committed
HHH-14918 Always process components containing an ID copy as we would any other FK
1 parent 6c53a9d commit ccd58ee

File tree

2 files changed

+14
-64
lines changed

2 files changed

+14
-64
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.hibernate.boot.spi.NaturalIdUniqueKeyBinder;
5858
import org.hibernate.cfg.AnnotatedClassType;
5959
import org.hibernate.cfg.AvailableSettings;
60-
import org.hibernate.cfg.CopyIdentifierComponentSecondPass;
6160
import org.hibernate.cfg.CreateKeySecondPass;
6261
import org.hibernate.cfg.FkSecondPass;
6362
import org.hibernate.cfg.IdGeneratorResolverSecondPass;
@@ -1504,7 +1503,6 @@ public Join locateJoin(Identifier tableName) {
15041503

15051504
private ArrayList<IdGeneratorResolverSecondPass> idGeneratorResolverSecondPassList;
15061505
private ArrayList<SetSimpleValueTypeSecondPass> setSimpleValueTypeSecondPassList;
1507-
private ArrayList<CopyIdentifierComponentSecondPass> copyIdentifierComponentSecondPasList;
15081506
private ArrayList<FkSecondPass> fkSecondPassList;
15091507
private ArrayList<CreateKeySecondPass> createKeySecondPasList;
15101508
private ArrayList<SecondaryTableSecondPass> secondaryTableSecondPassList;
@@ -1526,9 +1524,6 @@ public void addSecondPass(SecondPass secondPass, boolean onTopOfTheQueue) {
15261524
else if ( secondPass instanceof SetSimpleValueTypeSecondPass ) {
15271525
addSetSimpleValueTypeSecondPass( (SetSimpleValueTypeSecondPass) secondPass, onTopOfTheQueue );
15281526
}
1529-
else if ( secondPass instanceof CopyIdentifierComponentSecondPass ) {
1530-
addCopyIdentifierComponentSecondPass( (CopyIdentifierComponentSecondPass) secondPass, onTopOfTheQueue );
1531-
}
15321527
else if ( secondPass instanceof FkSecondPass ) {
15331528
addFkSecondPass( (FkSecondPass) secondPass, onTopOfTheQueue );
15341529
}
@@ -1576,15 +1571,6 @@ private void addIdGeneratorResolverSecondPass(IdGeneratorResolverSecondPass seco
15761571
addSecondPass( secondPass, idGeneratorResolverSecondPassList, onTopOfTheQueue );
15771572
}
15781573

1579-
private void addCopyIdentifierComponentSecondPass(
1580-
CopyIdentifierComponentSecondPass secondPass,
1581-
boolean onTopOfTheQueue) {
1582-
if ( copyIdentifierComponentSecondPasList == null ) {
1583-
copyIdentifierComponentSecondPasList = new ArrayList<>();
1584-
}
1585-
addSecondPass( secondPass, copyIdentifierComponentSecondPasList, onTopOfTheQueue );
1586-
}
1587-
15881574
private void addFkSecondPass(FkSecondPass secondPass, boolean onTopOfTheQueue) {
15891575
if ( fkSecondPassList == null ) {
15901576
fkSecondPassList = new ArrayList<>();
@@ -1635,8 +1621,6 @@ public void processSecondPasses(MetadataBuildingContext buildingContext) {
16351621
processSecondPasses( implicitColumnNamingSecondPassList );
16361622
processSecondPasses( setSimpleValueTypeSecondPassList );
16371623

1638-
processCopyIdentifierSecondPassesInOrder();
1639-
16401624
processFkSecondPassesInOrder();
16411625

16421626
processSecondPasses( createKeySecondPasList );
@@ -1661,14 +1645,6 @@ public void processSecondPasses(MetadataBuildingContext buildingContext) {
16611645
}
16621646
}
16631647

1664-
private void processCopyIdentifierSecondPassesInOrder() {
1665-
if ( copyIdentifierComponentSecondPasList == null ) {
1666-
return;
1667-
}
1668-
sortCopyIdentifierComponentSecondPasses();
1669-
processSecondPasses( copyIdentifierComponentSecondPasList );
1670-
}
1671-
16721648
private void processSecondPasses(ArrayList<? extends SecondPass> secondPasses) {
16731649
if ( secondPasses == null ) {
16741650
return;
@@ -1681,39 +1657,6 @@ private void processSecondPasses(ArrayList<? extends SecondPass> secondPasses) {
16811657
secondPasses.clear();
16821658
}
16831659

1684-
private void sortCopyIdentifierComponentSecondPasses() {
1685-
1686-
ArrayList<CopyIdentifierComponentSecondPass> sorted =
1687-
new ArrayList<>( copyIdentifierComponentSecondPasList.size() );
1688-
Set<CopyIdentifierComponentSecondPass> toSort = new HashSet<>( copyIdentifierComponentSecondPasList );
1689-
topologicalSort( sorted, toSort );
1690-
copyIdentifierComponentSecondPasList = sorted;
1691-
}
1692-
1693-
/* naive O(n^3) topological sort */
1694-
private void topologicalSort( List<CopyIdentifierComponentSecondPass> sorted, Set<CopyIdentifierComponentSecondPass> toSort ) {
1695-
while (!toSort.isEmpty()) {
1696-
CopyIdentifierComponentSecondPass independent = null;
1697-
1698-
searchForIndependent:
1699-
for ( CopyIdentifierComponentSecondPass secondPass : toSort ) {
1700-
for ( CopyIdentifierComponentSecondPass other : toSort ) {
1701-
if (secondPass.dependentUpon( other )) {
1702-
continue searchForIndependent;
1703-
}
1704-
}
1705-
independent = secondPass;
1706-
break;
1707-
}
1708-
if (independent == null) {
1709-
throw new MappingException( "cyclic dependency in derived identities" );
1710-
}
1711-
toSort.remove( independent );
1712-
sorted.add( independent );
1713-
}
1714-
}
1715-
1716-
17171660
private void processFkSecondPassesInOrder() {
17181661
if ( fkSecondPassList == null || fkSecondPassList.isEmpty() ) {
17191662
return;

hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import org.hibernate.AssertionFailure;
1717
import org.hibernate.MappingException;
1818
import org.hibernate.boot.model.naming.Identifier;
19-
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
20-
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
2119
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
2220
import org.hibernate.boot.model.relational.Database;
2321
import org.hibernate.boot.spi.MetadataBuildingContext;
@@ -33,7 +31,7 @@
3331
/**
3432
* @author Emmanuel Bernard
3533
*/
36-
public class CopyIdentifierComponentSecondPass implements SecondPass {
34+
public class CopyIdentifierComponentSecondPass extends FkSecondPass {
3735
private static final Logger log = Logger.getLogger( CopyIdentifierComponentSecondPass.class );
3836

3937
private final String referencedEntityName;
@@ -46,12 +44,25 @@ public CopyIdentifierComponentSecondPass(
4644
String referencedEntityName,
4745
Ejb3JoinColumn[] joinColumns,
4846
MetadataBuildingContext buildingContext) {
47+
super( comp, joinColumns );
4948
this.component = comp;
5049
this.referencedEntityName = referencedEntityName;
5150
this.buildingContext = buildingContext;
5251
this.joinColumns = joinColumns;
5352
}
5453

54+
@Override
55+
public String getReferencedEntityName() {
56+
return referencedEntityName;
57+
}
58+
59+
@Override
60+
public boolean isInPrimaryKey() {
61+
// This second pass is apparently only ever used to initialize composite identifiers
62+
return true;
63+
}
64+
65+
@Override
5566
@SuppressWarnings({ "unchecked" })
5667
public void doSecondPass(Map persistentClasses) throws MappingException {
5768
PersistentClass referencedPersistentClass = (PersistentClass) persistentClasses.get( referencedEntityName );
@@ -219,8 +230,4 @@ private void applyComponentColumnSizeValueToJoinColumn(Column column, Ejb3JoinCo
219230
mappingColumn.setPrecision( column.getPrecision() );
220231
mappingColumn.setScale( column.getScale() );
221232
}
222-
223-
public boolean dependentUpon( CopyIdentifierComponentSecondPass other ) {
224-
return this.referencedEntityName.equals( other.component.getOwner().getEntityName() );
225-
}
226233
}

0 commit comments

Comments
 (0)