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 authored and marko-bekhta committed Sep 25, 2023
1 parent 8e86dc8 commit b9a9c51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 @@ -83,8 +84,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 @@ -94,10 +94,9 @@ 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 @@ -121,7 +120,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
Original file line number Diff line number Diff line change
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 @@ -151,15 +150,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 b9a9c51

Please sign in to comment.