| Hi, Recently I've done huge migration from hibernate-search-3.0.0.GA to hibernate-search-orm-5.6.1.Final. In our project we have a lot of @Indexed entities and quite sophisticated hierarchy. There's abstract @Indexed @MappedSuperclass which has @Indexed subclasses. Simplifying thing it could be written like following:
@MappedSuperclass
@Indexed
public abstract static class A {
@Id
@GeneratedValue
public long id;
@Field(store = Store.YES)
@NumericField
public int parentRandom = new Random().nextInt();
}
@Entity
@Indexed
public static class B extends A {
@Field(store = Store.YES)
@NumericField
public int random = new Random().nextInt();
}
I found it very interesting, that after switch all the entities started to be populated in the index for class (we're using FSDirectoryProvider as a provider) A, even though I'm trying to index B instances. Quick analysis shows, that during creation of IndexManagerGroupHolder there's wrong name passed as first argument for org.hibernate.search.indexes.impl.IndexManagerHolder#getOrCreateGroupHolder. Following that further one could see, that in org.hibernate.search.indexes.impl.IndexManagerHolder#getIndexName there appears to be index name evaluation:
Class<?> aClass = cfg.getClassMapping( clazz.getName() );
XClass rootIndex = null;
do {
XClass currentClazz = reflectionManager.toXClass( aClass );
Indexed indexAnn = currentClazz.getAnnotation( Indexed.class );
if ( indexAnn != null ) {
if ( indexAnn.index().length() != 0 ) {
return indexAnn.index();
}
else {
rootIndex = currentClazz;
}
}
aClass = aClass.getSuperclass();
}
while ( aClass != null );
which then followed by return statement:
if ( rootIndex != null ) {
return rootIndex.getName();
}
If I do get comment before the loop right, this method should return the most specific index name either from @Index.name or fully-qualified class name of the @Indexed entity. Question is is my understanding correct? If so that in my case, when indexing subclass B I should get as an index name fully qualified name of class B. Problem is, that I get fqcn A instead. Problem appears to be serious, when one's using exclusive_index_use=true, which is default now. |