HHH-16661 Use qualified table names for entity name by table name map

This commit is contained in:
Marco Belladelli 2023-05-30 11:26:31 +02:00
parent 53d474d85f
commit bf1068be7e
2 changed files with 18 additions and 9 deletions

View File

@ -537,7 +537,8 @@ else if ( !elementType.isEntityType() ) {
} }
else { else {
entityNameByTableNameMap = AbstractEntityPersister.getEntityNameByTableNameMap( entityNameByTableNameMap = AbstractEntityPersister.getEntityNameByTableNameMap(
creationContext.getBootModel().getEntityBinding( elementPersister.getEntityName() ) creationContext.getBootModel().getEntityBinding( elementPersister.getEntityName() ),
factory.getSqlStringGenerationContext()
); );
} }
filterHelper = new FilterHelper( collectionBootDescriptor.getFilters(), entityNameByTableNameMap, factory ); filterHelper = new FilterHelper( collectionBootDescriptor.getFilters(), entityNameByTableNameMap, factory );

View File

@ -44,6 +44,7 @@
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
import org.hibernate.StaleStateException; import org.hibernate.StaleStateException;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
@ -765,9 +766,14 @@ public AbstractEntityPersister(
propertyDefinedOnSubclass = toBooleanArray( definedBySubclass ); propertyDefinedOnSubclass = toBooleanArray( definedBySubclass );
// Handle any filters applied to the class level // Handle any filters applied to the class level
filterHelper = isNotEmpty( persistentClass.getFilters() ) filterHelper = isNotEmpty( persistentClass.getFilters() ) ? new FilterHelper(
? new FilterHelper( persistentClass.getFilters(), getEntityNameByTableNameMap( persistentClass ), factory ) persistentClass.getFilters(),
: null; getEntityNameByTableNameMap(
persistentClass,
factory.getSqlStringGenerationContext()
),
factory
) : null;
useReferenceCacheEntries = shouldUseReferenceCacheEntries( creationContext.getSessionFactoryOptions() ); useReferenceCacheEntries = shouldUseReferenceCacheEntries( creationContext.getSessionFactoryOptions() );
cacheEntryHelper = buildCacheEntryHelper( creationContext.getSessionFactoryOptions() ); cacheEntryHelper = buildCacheEntryHelper( creationContext.getSessionFactoryOptions() );
@ -826,20 +832,22 @@ private SingleIdEntityLoader<?> createSingleIdEntityLoader(LoadQueryInfluencers
} }
} }
public static Map<String, String> getEntityNameByTableNameMap(PersistentClass persistentClass) { public static Map<String, String> getEntityNameByTableNameMap(
PersistentClass persistentClass,
SqlStringGenerationContext stringGenerationContext) {
final Map<String, String> entityNameByTableNameMap = new HashMap<>(); final Map<String, String> entityNameByTableNameMap = new HashMap<>();
PersistentClass superType = persistentClass.getSuperPersistentClass(); PersistentClass superType = persistentClass.getSuperPersistentClass();
while ( superType != null ) { while ( superType != null ) {
entityNameByTableNameMap.put( superType.getTable().getName(), superType.getEntityName() ); entityNameByTableNameMap.put( superType.getTable().getQualifiedName( stringGenerationContext ), superType.getEntityName() );
for ( Join join : superType.getJoins() ) { for ( Join join : superType.getJoins() ) {
entityNameByTableNameMap.put( join.getTable().getName(), superType.getEntityName() ); entityNameByTableNameMap.put( join.getTable().getQualifiedName( stringGenerationContext ), superType.getEntityName() );
} }
superType = superType.getSuperPersistentClass(); superType = superType.getSuperPersistentClass();
} }
for ( PersistentClass subclass : persistentClass.getSubclassClosure() ) { for ( PersistentClass subclass : persistentClass.getSubclassClosure() ) {
entityNameByTableNameMap.put( subclass.getTable().getName(), subclass.getEntityName() ); entityNameByTableNameMap.put( subclass.getTable().getQualifiedName( stringGenerationContext ), subclass.getEntityName() );
for ( Join join : subclass.getJoins() ) { for ( Join join : subclass.getJoins() ) {
entityNameByTableNameMap.put( join.getTable().getName(), subclass.getEntityName() ); entityNameByTableNameMap.put( join.getTable().getQualifiedName( stringGenerationContext ), subclass.getEntityName() );
} }
} }
return entityNameByTableNameMap; return entityNameByTableNameMap;