diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java b/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java index 2fa6d42228..0a578055a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java @@ -478,7 +478,7 @@ public class BinderHelper { catch (MappingException me) { //swallow it } - Iterator joins = current.getJoinIterator(); + Iterator joins = current.getJoinIterator(); while ( !found && joins.hasNext() ) { result = joins.next(); currentTable = ( (Join) result ).getTable(); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java index 7214edbe48..ca03ac283e 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java @@ -6,7 +6,6 @@ */ package org.hibernate.cfg; -import java.util.Iterator; import java.util.Map; import jakarta.persistence.JoinColumn; @@ -27,7 +26,6 @@ import org.hibernate.mapping.ManyToOne; import org.hibernate.mapping.OneToOne; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; -import org.hibernate.mapping.Selectable; import org.hibernate.mapping.SortableValue; import org.hibernate.type.ForeignKeyDirection; @@ -176,10 +174,8 @@ public class OneToOneSecondPass implements SecondPass { propertyHolder.addProperty( prop, inferredData.getDeclaringClass() ); } else if ( otherSideProperty.getValue() instanceof ManyToOne ) { - Iterator it = otherSide.getJoinIterator(); Join otherSideJoin = null; - while ( it.hasNext() ) { - Join otherSideJoinValue = it.next(); + for ( Join otherSideJoinValue : otherSide.getJoins() ) { if ( otherSideJoinValue.containsProperty( otherSideProperty ) ) { otherSideJoin = otherSideJoinValue; break; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java index af9cb85d5b..b1d879cfab 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java @@ -2020,10 +2020,8 @@ public abstract class CollectionBinder { } else { //find the appropriate reference key, can be in a join - Iterator joinsIt = referencedEntity.getJoinIterator(); KeyValue key = null; - while ( joinsIt.hasNext() ) { - Join join = joinsIt.next(); + for ( Join join : referencedEntity.getJoins() ) { if ( join.containsProperty( property ) ) { key = join.getKey(); break; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java index 2cb3da560f..5b472a473d 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java @@ -31,6 +31,7 @@ import org.hibernate.MappingException; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Columns; import org.hibernate.annotations.Comment; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; @@ -844,12 +845,12 @@ public class EntityBinder { * Those operations has to be done after the id definition of the persistence class. * ie after the properties parsing */ - Iterator joins = secondaryTables.values().iterator(); - Iterator joinColumns = secondaryTableJoins.values().iterator(); + Iterator joins = secondaryTables.values().iterator(); + Iterator joinColumns = secondaryTableJoins.values().iterator(); while ( joins.hasNext() ) { Object uncastedColumn = joinColumns.next(); - Join join = (Join) joins.next(); + Join join = joins.next(); createPrimaryColumnsToSecondaryTable( uncastedColumn, propertyHolder, join ); } } @@ -1203,16 +1204,13 @@ public class EntityBinder { //comment and index are processed here if ( table == null ) return; String appliedTable = table.appliesTo(); - Iterator tables = persistentClass.getTableClosureIterator(); Table hibTable = null; - while ( tables.hasNext() ) { - Table pcTable = (Table) tables.next(); + for ( Table pcTable : persistentClass.getTableClosure() ) { if ( pcTable.getQuotedName().equals( appliedTable ) ) { //we are in the correct table to find columns hibTable = pcTable; break; } - hibTable = null; } if ( hibTable == null ) { //maybe a join/secondary table diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java index da9923701a..be263d5259 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java @@ -323,6 +323,9 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl @Deprecated(since = "6.0") public abstract Iterator getPropertyClosureIterator(); + public abstract List getTableClosure(); + + @Deprecated(since = "6.0") public abstract Iterator
getTableClosureIterator(); public abstract Iterator getKeyClosureIterator(); @@ -360,10 +363,20 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return new JoinedList<>( lists ); } + @Deprecated(since = "6.0") public Iterator getSubclassJoinClosureIterator() { return new JoinedIterator<>( getJoinClosureIterator(), subclassJoins.iterator() ); } + public List getSubclassJoinClosure() { + return new JoinedList<>( getJoinClosure(), subclassJoins ); + } + + public List
getSubclassTableClosure() { + return new JoinedList<>( getTableClosure(), subclassTables ); + } + + @Deprecated(since = "6.0") public Iterator
getSubclassTableClosureIterator() { return new JoinedIterator<>( getTableClosureIterator(), subclassTables.iterator() ); } @@ -712,10 +725,20 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl return getClass().getName() + '(' + getEntityName() + ')'; } + public List getJoins() { + return joins; + } + + public List getJoinClosure() { + return joins; + } + + @Deprecated(since = "6.0") public Iterator getJoinIterator() { return joins.iterator(); } + @Deprecated(since = "6.0") public Iterator getJoinClosureIterator() { return joins.iterator(); } @@ -739,9 +762,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl public int getJoinNumber(Property prop) { int result = 1; - Iterator iter = getSubclassJoinClosureIterator(); - while ( iter.hasNext() ) { - Join join = iter.next(); + for ( Join join : getSubclassJoinClosure() ) { if ( join.containsProperty( prop ) ) { return result; } @@ -998,10 +1019,8 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl } checkColumnDuplication( cols, getDiscriminator() ); checkPropertyColumnDuplication( cols, getNonDuplicatedProperties() ); - Iterator iter = getJoinIterator(); - while ( iter.hasNext() ) { + for ( Join join : getJoins() ) { cols.clear(); - Join join = iter.next(); checkColumnDuplication( cols, join.getKey() ); checkPropertyColumnDuplication( cols, join.getProperties() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java index f69f2c4f7d..ed595ac884 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java @@ -136,11 +136,16 @@ public class RootClass extends PersistentClass implements TableOwner { return getProperties(); } - @Override + @Override @Deprecated public Iterator
getTableClosureIterator() { return new SingletonIterator<>( getTable() ); } + @Override + public List
getTableClosure() { + return List.of( getTable() ); + } + @Override public Iterator getKeyClosureIterator() { return new SingletonIterator<>( getKey() ); @@ -344,13 +349,12 @@ public class RootClass extends PersistentClass implements TableOwner { return synchronizedTables; } - @SuppressWarnings("UnnecessaryUnboxing") public Set
getIdentityTables() { Set
tables = new HashSet<>(); - Iterator iter = getSubclassClosureIterator(); + Iterator iter = getSubclassClosureIterator(); while ( iter.hasNext() ) { - PersistentClass clazz = (PersistentClass) iter.next(); - if ( clazz.isAbstract() == null || !clazz.isAbstract().booleanValue() ) { + PersistentClass clazz = iter.next(); + if ( clazz.isAbstract() == null || !clazz.isAbstract() ) { tables.add( clazz.getIdentityTable() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java index d8fa32a30b..70820bfb7c 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Subclass.java @@ -38,10 +38,12 @@ public class Subclass extends PersistentClass { this.subclassId = superclass.nextSubclassId(); } + @Override int nextSubclassId() { return getSuperclass().nextSubclassId(); } + @Override public int getSubclassId() { return subclassId; } @@ -51,55 +53,74 @@ public class Subclass extends PersistentClass { return getSuperclass().getNaturalIdCacheRegionName(); } + @Override public String getCacheConcurrencyStrategy() { return getRootClass().getCacheConcurrencyStrategy(); } + @Override public RootClass getRootClass() { return getSuperclass().getRootClass(); } + @Override public PersistentClass getSuperclass() { return superclass; } + @Override public Property getIdentifierProperty() { return getSuperclass().getIdentifierProperty(); } + @Override public Property getDeclaredIdentifierProperty() { return null; } + @Override public KeyValue getIdentifier() { return getSuperclass().getIdentifier(); } + + @Override public boolean hasIdentifierProperty() { return getSuperclass().hasIdentifierProperty(); } + + @Override public Value getDiscriminator() { return getSuperclass().getDiscriminator(); } + + @Override public boolean isMutable() { return getSuperclass().isMutable(); } + + @Override public boolean isInherited() { return true; } + + @Override public boolean isPolymorphic() { return true; } + @Override public void addProperty(Property p) { super.addProperty(p); getSuperclass().addSubclassProperty(p); } + @Override public void addMappedsuperclassProperty(Property p) { super.addMappedsuperclassProperty( p ); getSuperclass().addSubclassProperty(p); } + @Override public void addJoin(Join j) { super.addJoin(j); getSuperclass().addSubclassJoin(j); @@ -110,7 +131,7 @@ public class Subclass extends PersistentClass { return new JoinedList<>( getSuperclass().getPropertyClosure(), getProperties() ); } - @Deprecated + @Deprecated @Override public Iterator getPropertyClosureIterator() { return new JoinedIterator<>( getSuperclass().getPropertyClosureIterator(), @@ -118,60 +139,86 @@ public class Subclass extends PersistentClass { ); } + @Deprecated @Override public Iterator
getTableClosureIterator() { return new JoinedIterator<>( getSuperclass().getTableClosureIterator(), new SingletonIterator<>( getTable() ) ); } + + @Override + public List
getTableClosure() { + return new JoinedList<>( + getSuperclass().getTableClosure(), + List.of( getTable() ) + ); + } + + @Override public Iterator getKeyClosureIterator() { return new JoinedIterator<>( getSuperclass().getKeyClosureIterator(), new SingletonIterator<>( getKey() ) ); } + + @Override protected void addSubclassProperty(Property p) { super.addSubclassProperty(p); getSuperclass().addSubclassProperty(p); } + + @Override protected void addSubclassJoin(Join j) { super.addSubclassJoin(j); getSuperclass().addSubclassJoin(j); } + @Override protected void addSubclassTable(Table table) { super.addSubclassTable(table); getSuperclass().addSubclassTable(table); } + @Override public boolean isVersioned() { return getSuperclass().isVersioned(); } + + @Override public Property getVersion() { return getSuperclass().getVersion(); } + @Override public Property getDeclaredVersion() { return null; } + @Override public boolean hasEmbeddedIdentifier() { return getSuperclass().hasEmbeddedIdentifier(); } + + @Override public Class getEntityPersisterClass() { return classPersisterClass == null ? getSuperclass().getEntityPersisterClass() : classPersisterClass; } + @Override public Table getRootTable() { return getSuperclass().getRootTable(); } + @Override public KeyValue getKey() { return getSuperclass().getIdentifier(); } + @Override public boolean isExplicitPolymorphism() { return getSuperclass().isExplicitPolymorphism(); } @@ -180,10 +227,12 @@ public class Subclass extends PersistentClass { this.superclass = superclass; } + @Override public String getWhere() { return getSuperclass().getWhere(); } + @Override public boolean isJoinedSubclass() { return getTable()!=getRootTable(); } @@ -195,18 +244,28 @@ public class Subclass extends PersistentClass { getKey().createForeignKeyOfEntity( getSuperclass().getEntityName() ); } + @Override public void setEntityPersisterClass(Class classPersisterClass) { this.classPersisterClass = classPersisterClass; } + + @Override public int getJoinClosureSpan() { return getSuperclass().getJoinClosureSpan() + super.getJoinClosureSpan(); } + @Override public int getPropertyClosureSpan() { return getSuperclass().getPropertyClosureSpan() + super.getPropertyClosureSpan(); } + @Override + public List getJoinClosure() { + return new JoinedList<>( getSuperclass().getJoinClosure(), super.getJoinClosure() ); + } + + @Deprecated(since = "6.0") public Iterator getJoinClosureIterator() { return new JoinedIterator<>( getSuperclass().getJoinClosureIterator(), @@ -214,26 +273,33 @@ public class Subclass extends PersistentClass { ); } + + @Override public boolean isClassOrSuperclassJoin(Join join) { return super.isClassOrSuperclassJoin(join) || getSuperclass().isClassOrSuperclassJoin(join); } + @Override public boolean isClassOrSuperclassTable(Table table) { return super.isClassOrSuperclassTable(table) || getSuperclass().isClassOrSuperclassTable(table); } + @Override public Table getTable() { return getSuperclass().getTable(); } + @Override public boolean isForceDiscriminator() { return getSuperclass().isForceDiscriminator(); } + @Override public boolean isDiscriminatorInsertable() { return getSuperclass().isDiscriminatorInsertable(); } + @Override public java.util.Set getSynchronizedTables() { HashSet result = new HashSet<>(); result.addAll(synchronizedTables); @@ -241,21 +307,25 @@ public class Subclass extends PersistentClass { return result; } + @Override public Object accept(PersistentClassVisitor mv) { return mv.accept(this); } + @Override public java.util.List getFilters() { java.util.List filters = new ArrayList<>(super.getFilters()); filters.addAll(getSuperclass().getFilters()); return filters; } + @Override public boolean hasSubselectLoadableCollections() { return super.hasSubselectLoadableCollections() || getSuperclass().hasSubselectLoadableCollections(); } + @Override public String getTuplizerImplClassName(RepresentationMode mode) { String impl = super.getTuplizerImplClassName( mode ); if ( impl == null ) { @@ -264,6 +334,7 @@ public class Subclass extends PersistentClass { return impl; } + @Override public Map getTuplizerMap() { Map specificTuplizerDefs = super.getTuplizerMap(); Map superclassTuplizerDefs = getSuperclass().getTuplizerMap(); @@ -282,6 +353,7 @@ public class Subclass extends PersistentClass { } } + @Override public Component getIdentifierMapper() { return superclass.getIdentifierMapper(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index ed892e0374..6ebeed1df9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -223,9 +223,7 @@ public class ToOneAttributeMapping .getEntityBinding( manyToOne.getReferencedEntityName() ); if ( cardinality == Cardinality.LOGICAL_ONE_TO_ONE ) { // Handle join table cases - final Iterator joinClosureIterator = entityBinding.getJoinClosureIterator(); - while ( joinClosureIterator.hasNext() ) { - final Join join = joinClosureIterator.next(); + for ( Join join : entityBinding.getJoinClosure() ) { if ( join.getPersistentClass().getEntityName().equals( entityBinding.getEntityName() ) && join.getPropertySpan() == 1 && join.getTable() == manyToOne.getTable() diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index 2e2b858e6d..228c0ef62a 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -282,10 +282,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { isNullableTable = new boolean[tableSpan]; isInverseTable = new boolean[tableSpan]; - Iterator joinItr = persistentClass.getJoinClosureIterator(); - for ( int tableIndex = 0; joinItr.hasNext(); tableIndex++ ) { - Join join = joinItr.next(); - + int tableIndex = 0; + for ( Join join : persistentClass.getJoinClosure() ) { isNullableTable[tableIndex] = join.isOptional(); isInverseTable[tableIndex] = join.isInverse(); @@ -311,6 +309,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { keyColumnReaders.add( keyColReaders ); keyColumnReaderTemplates.add( keyColReaderTemplates ); cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getJdbcServices().getDialect().supportsCascadeDelete() ); + + tableIndex++; } naturalOrderTableNames = ArrayHelper.toStringArray( tableNames ); @@ -327,18 +327,16 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { ArrayList isNullables = new ArrayList<>(); keyColumns = new ArrayList<>(); - tItr = persistentClass.getSubclassTableClosureIterator(); - while ( tItr.hasNext() ) { - Table tab = tItr.next(); - isConcretes.add( persistentClass.isClassOrSuperclassTable( tab ) ); + for ( Table table : persistentClass.getSubclassTableClosure() ) { + isConcretes.add( persistentClass.isClassOrSuperclassTable( table ) ); isDeferreds.add( Boolean.FALSE ); isLazies.add( Boolean.FALSE ); isInverses.add( Boolean.FALSE ); isNullables.add( Boolean.FALSE ); - final String tableName = determineTableName( tab ); + final String tableName = determineTableName( table ); subclassTableNames.add( tableName ); String[] key = new String[idColumnSpan]; - List columns = tab.getPrimaryKey().getColumns(); + List columns = table.getPrimaryKey().getColumns(); for ( int k = 0; k < idColumnSpan; k++ ) { key[k] = columns.get(k).getQuotedName( factory.getJdbcServices().getDialect() ); } @@ -346,9 +344,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } //Add joins - joinItr = persistentClass.getSubclassJoinClosureIterator(); - while ( joinItr.hasNext() ) { - final Join join = joinItr.next(); + for ( Join join : persistentClass.getSubclassJoinClosure() ) { final Table joinTable = join.getTable(); isConcretes.add( persistentClass.isClassOrSuperclassTable( joinTable ) ); @@ -446,11 +442,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { throw new AssertionFailure( "Tablespan does not match height of joined-subclass hiearchy." ); } - joinItr = persistentClass.getJoinClosureIterator(); int j = coreTableSpan; - while ( joinItr.hasNext() ) { - Join join = joinItr.next(); - + for ( Join join : persistentClass.getJoinClosure() ) { isInverseTable[j] = join.isInverse(); isNullableTable[j] = join.isOptional(); @@ -746,9 +739,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping ); - Iterator itr = persistentClass.getJoinIterator(); - while ( itr.hasNext() ) { - final Join join = itr.next(); + for ( Join join : persistentClass.getJoins() ) { final String secondaryTableName = join.getTable().getQualifiedName( factory.getSqlStringGenerationContext() ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index a0e27d1b22..ec5f3b9b96 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -187,11 +187,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // JOINS - Iterator joinIter = persistentClass.getJoinClosureIterator(); int j = 1; final Dialect dialect = factory.getJdbcServices().getDialect(); - while ( joinIter.hasNext() ) { - Join join = joinIter.next(); + for ( Join join : persistentClass.getJoinClosure() ) { qualifiedTableNames[j] = determineTableName( join.getTable() ); isInverseTable[j] = join.isInverse(); isNullableTable[j] = join.isOptional(); @@ -253,9 +251,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { isInverses.add( Boolean.FALSE ); isNullables.add( Boolean.FALSE ); isLazies.add( Boolean.FALSE ); - joinIter = persistentClass.getSubclassJoinClosureIterator(); - while ( joinIter.hasNext() ) { - Join join = joinIter.next(); + for ( Join join : persistentClass.getSubclassJoinClosure() ) { isConcretes.add( persistentClass.isClassOrSuperclassTable( join.getTable() ) ); isClassOrSuperclassJoins.add( persistentClass.isClassOrSuperclassJoin( join ) ); isInverses.add( join.isInverse() ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index a1cd73fcf1..988291283e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -182,9 +182,8 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { } HashSet subclassTables = new HashSet<>(); - Iterator
subclassTableIter = persistentClass.getSubclassTableClosureIterator(); - while ( subclassTableIter.hasNext() ) { - subclassTables.add( determineTableName( subclassTableIter.next() ) ); + for ( Table table : persistentClass.getSubclassTableClosure() ) { + subclassTables.add( determineTableName( table ) ); } subclassSpaces = ArrayHelper.toStringArray( subclassTables ); @@ -210,14 +209,12 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { int idColumnSpan = getIdentifierColumnSpan(); ArrayList tableNames = new ArrayList<>(); ArrayList keyColumns = new ArrayList<>(); - Iterator
tableIter = persistentClass.getSubclassTableClosureIterator(); - while ( tableIter.hasNext() ) { - Table tab = tableIter.next(); - if ( !tab.isAbstractUnionTable() ) { - final String tableName = determineTableName( tab ); + for ( Table table : persistentClass.getSubclassTableClosure() ) { + if ( !table.isAbstractUnionTable() ) { + final String tableName = determineTableName( table ); tableNames.add( tableName ); String[] key = new String[idColumnSpan]; - List columns = tab.getPrimaryKey().getColumns(); + List columns = table.getPrimaryKey().getColumns(); for ( int k = 0; k < idColumnSpan; k++ ) { key[k] = columns.get(k).getQuotedName( factory.getJdbcServices().getDialect() ); } @@ -468,14 +465,10 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { ); } - HashSet columns = new LinkedHashSet<>(); - Iterator
titer = model.getSubclassTableClosureIterator(); - while ( titer.hasNext() ) { - Table table = titer.next(); + Set columns = new LinkedHashSet<>(); + for ( Table table : model.getSubclassTableClosure() ) { if ( !table.isAbstractUnionTable() ) { - for ( Column column : table.getColumns() ) { - columns.add( column ); - } + columns.addAll( table.getColumns() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java b/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java index 25c967b938..8b2403b7bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java @@ -28,9 +28,9 @@ public class DynamicMapInstantiator implements Instantiator { this.roleName = mappingInfo.getEntityName(); isInstanceEntityNames.add( roleName ); if ( mappingInfo.hasSubclasses() ) { - Iterator itr = mappingInfo.getSubclassClosureIterator(); + Iterator itr = mappingInfo.getSubclassClosureIterator(); while ( itr.hasNext() ) { - final PersistentClass subclassInfo = ( PersistentClass ) itr.next(); + final PersistentClass subclassInfo = itr.next(); isInstanceEntityNames.add( subclassInfo.getEntityName() ); } }