diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index b50f0bac5c..64501db568 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -30,6 +30,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.ArrayHelper; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -118,8 +119,8 @@ public class EntityMetamodel implements Serializable { private final boolean explicitPolymorphism; private final boolean inherited; private final boolean hasSubclasses; - private final Set subclassEntityNames = new HashSet(); - private final Map entityNameByInheritenceClassMap = new HashMap(); + private final Set subclassEntityNames; + private final Map entityNameByInheritenceClassMap; private final EntityMode entityMode; private final EntityTuplizer entityTuplizer; @@ -397,19 +398,23 @@ public class EntityMetamodel implements Serializable { hasMutableProperties = foundMutable; iter = persistentClass.getSubclassIterator(); + final Set subclassEntityNamesLocal = new HashSet<>(); while ( iter.hasNext() ) { - subclassEntityNames.add( ( (PersistentClass) iter.next() ).getEntityName() ); + subclassEntityNamesLocal.add( ( (PersistentClass) iter.next() ).getEntityName() ); } - subclassEntityNames.add( name ); + subclassEntityNamesLocal.add( name ); + subclassEntityNames = CollectionHelper.toSmallSet( subclassEntityNamesLocal ); + HashMap entityNameByInheritenceClassMapLocal = new HashMap(); if ( persistentClass.hasPojoRepresentation() ) { - entityNameByInheritenceClassMap.put( persistentClass.getMappedClass(), persistentClass.getEntityName() ); + entityNameByInheritenceClassMapLocal.put( persistentClass.getMappedClass(), persistentClass.getEntityName() ); iter = persistentClass.getSubclassIterator(); while ( iter.hasNext() ) { final PersistentClass pc = ( PersistentClass ) iter.next(); - entityNameByInheritenceClassMap.put( pc.getMappedClass(), pc.getEntityName() ); + entityNameByInheritenceClassMapLocal.put( pc.getMappedClass(), pc.getEntityName() ); } } + entityNameByInheritenceClassMap = CollectionHelper.toSmallMap( entityNameByInheritenceClassMapLocal ); entityMode = persistentClass.hasPojoRepresentation() ? EntityMode.POJO : EntityMode.MAP; final EntityTuplizerFactory entityTuplizerFactory = sessionFactoryOptions.getEntityTuplizerFactory(); @@ -963,7 +968,7 @@ public class EntityMetamodel implements Serializable { * @return The mapped entity-name, or null if no such mapping was found. */ public String findEntityNameByEntityClass(Class inheritenceClass) { - return ( String ) entityNameByInheritenceClassMap.get( inheritenceClass ); + return entityNameByInheritenceClassMap.get( inheritenceClass ); } @Override