Skip to content

Commit

Permalink
HSEARCH-4482 Avoid uses of Hibernate ORM's org.hibernate.tuple.entity…
Browse files Browse the repository at this point in the history
….EntityMetamodel internally where possible
  • Loading branch information
yrodiere committed Jan 2, 2023
1 parent f79d0bc commit d059ad5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Expand Up @@ -22,6 +22,7 @@
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.mapping.Property;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.search.mapper.orm.logging.impl.Log;
import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis;
Expand Down Expand Up @@ -82,8 +83,7 @@ public static EntityPersister toRootEntityType(SessionFactoryImplementor session
return metamodel.getEntityDescriptor( rootEntityName );
}

public static EntityPersister toMostSpecificCommonEntitySuperType(MappingMetamodel metamodel,
EntityPersister type1, EntityPersister type2) {
public static EntityPersister toMostSpecificCommonEntitySuperType(EntityPersister type1, EntityPersister type2) {
/*
* We need to rely on Hibernate ORM's SPIs: this is complex stuff.
* For example there may be class hierarchies such as A > B > C
Expand All @@ -93,9 +93,8 @@ public static EntityPersister toMostSpecificCommonEntitySuperType(MappingMetamod
*/
EntityPersister superTypeCandidate = type1;
while ( superTypeCandidate != null && !isSuperTypeOf( superTypeCandidate, type2 ) ) {
String superSuperTypeEntityName = superTypeCandidate.getEntityMetamodel().getSuperclass();
superTypeCandidate = superSuperTypeEntityName == null ? null
: metamodel.getEntityDescriptor( superSuperTypeEntityName ).getEntityPersister();
EntityMappingType superSuperType = superTypeCandidate.getSuperMappingType();
superTypeCandidate = superSuperType == null ? null : superSuperType.getEntityPersister();
}
if ( superTypeCandidate == null ) {
throw new AssertionFailure(
Expand All @@ -119,7 +118,7 @@ public static boolean targetsAllConcreteSubTypes(SessionFactoryImplementor sessi
MappingMetamodel metamodel = sessionFactory.getMappingMetamodel();
int concreteSubTypesCount = 0;
for ( String subClassEntityName : subClassEntityNames ) {
if ( !metamodel.getEntityDescriptor( subClassEntityName ).getEntityMetamodel().isAbstract() ) {
if ( !metamodel.getEntityDescriptor( subClassEntityName ).isAbstract() ) {
++concreteSubTypesCount;
}
}
Expand Down
Expand Up @@ -12,7 +12,6 @@
import org.hibernate.AssertionFailure;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.search.mapper.orm.common.impl.HibernateOrmUtils;
import org.hibernate.search.mapper.orm.search.loading.EntityLoadingCacheLookupStrategy;
Expand Down Expand Up @@ -149,15 +148,14 @@ private PojoSelectionEntityLoader<?> doCreate(EntityPersister entityPersister,

private static EntityPersister toMostSpecificCommonEntitySuperType(SessionImplementor session,
Iterable<? extends LoadingTypeContext<?>> targetEntityTypeContexts) {
MappingMetamodel metamodel = session.getSessionFactory().getMappingMetamodel();
EntityPersister result = null;
for ( LoadingTypeContext<?> targetTypeContext : targetEntityTypeContexts ) {
EntityPersister type = targetTypeContext.entityPersister();
if ( result == null ) {
result = type;
}
else {
result = HibernateOrmUtils.toMostSpecificCommonEntitySuperType( metamodel, result, type );
result = HibernateOrmUtils.toMostSpecificCommonEntitySuperType( result, type );
}
}
return result;
Expand Down

0 comments on commit d059ad5

Please sign in to comment.