We're updating the issue view to help you get more done. 

IndexManagerHolder picks up full name from the hierarchy root



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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 //get the most specialized (ie subclass > superclass) non default index name //if none extract the name from the most generic (superclass > subclass) @Indexed class in the hierarchy //FIXME I'm inclined to get rid of the default value 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:

1 2 3 4 //there is nobody out there with a non default @Indexed.index 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 of A instead.

Problem appears to be serious, when one's using exclusive_index_use=true, which is default now.







Sergey Ustimenko


Suitable for new contributors

Yes, likely

Pull Request


Feedback Requested