Skip to content

Commit 8ba7666

Browse files
yrodieremarko-bekhta
authored andcommitted
HSEARCH-4482 Avoid uses of Hibernate ORM's org.hibernate.tuple.entity.EntityMetamodel internally where possible
1 parent 0950bbd commit 8ba7666

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

mapper/orm/src/main/java/org/hibernate/search/mapper/orm/common/impl/HibernateOrmUtils.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.hibernate.engine.spi.SessionImplementor;
2424
import org.hibernate.mapping.Property;
2525
import org.hibernate.metamodel.MappingMetamodel;
26+
import org.hibernate.metamodel.mapping.EntityMappingType;
2627
import org.hibernate.persister.entity.EntityPersister;
2728
import org.hibernate.search.mapper.orm.logging.impl.Log;
2829
import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis;
@@ -83,8 +84,7 @@ public static EntityPersister toRootEntityType(SessionFactoryImplementor session
8384
return metamodel.getEntityDescriptor( rootEntityName );
8485
}
8586

86-
public static EntityPersister toMostSpecificCommonEntitySuperType(MappingMetamodel metamodel,
87-
EntityPersister type1, EntityPersister type2) {
87+
public static EntityPersister toMostSpecificCommonEntitySuperType(EntityPersister type1, EntityPersister type2) {
8888
/*
8989
* We need to rely on Hibernate ORM's SPIs: this is complex stuff.
9090
* For example there may be class hierarchies such as A > B > C
@@ -94,10 +94,9 @@ public static EntityPersister toMostSpecificCommonEntitySuperType(MappingMetamod
9494
*/
9595
EntityPersister superTypeCandidate = type1;
9696
while ( superTypeCandidate != null && !isSuperTypeOf( superTypeCandidate, type2 ) ) {
97-
String superSuperTypeEntityName = superTypeCandidate.getEntityMetamodel().getSuperclass();
98-
superTypeCandidate = superSuperTypeEntityName == null
99-
? null
100-
: metamodel.getEntityDescriptor( superSuperTypeEntityName ).getEntityPersister();
97+
EntityMappingType superSuperType = superTypeCandidate.getSuperMappingType();
98+
superTypeCandidate = superSuperType == null
99+
? null : superSuperType.getEntityPersister();
101100
}
102101
if ( superTypeCandidate == null ) {
103102
throw new AssertionFailure(
@@ -121,7 +120,7 @@ public static boolean targetsAllConcreteSubTypes(SessionFactoryImplementor sessi
121120
MappingMetamodel metamodel = sessionFactory.getMappingMetamodel();
122121
int concreteSubTypesCount = 0;
123122
for ( String subClassEntityName : subClassEntityNames ) {
124-
if ( !metamodel.getEntityDescriptor( subClassEntityName ).getEntityMetamodel().isAbstract() ) {
123+
if ( !metamodel.getEntityDescriptor( subClassEntityName ).isAbstract() ) {
125124
++concreteSubTypesCount;
126125
}
127126
}

mapper/orm/src/main/java/org/hibernate/search/mapper/orm/loading/impl/HibernateOrmEntityIdEntityLoadingStrategy.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.hibernate.AssertionFailure;
1313
import org.hibernate.engine.spi.SessionFactoryImplementor;
1414
import org.hibernate.engine.spi.SessionImplementor;
15-
import org.hibernate.metamodel.MappingMetamodel;
1615
import org.hibernate.persister.entity.EntityPersister;
1716
import org.hibernate.search.mapper.orm.common.impl.HibernateOrmUtils;
1817
import org.hibernate.search.mapper.orm.search.loading.EntityLoadingCacheLookupStrategy;
@@ -151,15 +150,14 @@ private PojoSelectionEntityLoader<?> doCreate(EntityPersister entityPersister,
151150

152151
private static EntityPersister toMostSpecificCommonEntitySuperType(SessionImplementor session,
153152
Iterable<? extends LoadingTypeContext<?>> targetEntityTypeContexts) {
154-
MappingMetamodel metamodel = session.getSessionFactory().getMappingMetamodel();
155153
EntityPersister result = null;
156154
for ( LoadingTypeContext<?> targetTypeContext : targetEntityTypeContexts ) {
157155
EntityPersister type = targetTypeContext.entityPersister();
158156
if ( result == null ) {
159157
result = type;
160158
}
161159
else {
162-
result = HibernateOrmUtils.toMostSpecificCommonEntitySuperType( metamodel, result, type );
160+
result = HibernateOrmUtils.toMostSpecificCommonEntitySuperType( result, type );
163161
}
164162
}
165163
return result;

0 commit comments

Comments
 (0)