Question

I use Hibernate Search programmatic api and I have configurable boosting for each entity. Configuration can be read through service which I need to access in mapping factory. Is it possible to get this bean somehow inside SearchMappingFactory? The problem is that spring context is not fully created at the moment the search mapping needs beans from it.

 public class SearchMappingFactory{

   @Factory
   public SearchMapping getSearchMapping() {
       SearchMapping searchMapping = new SearchMapping();

       // here I need to read configuration using configurationService
       // ... define mapping ...

       return searchMapping;
   }
 }

Then I set this mapping in sessionFactory this way

 hibernateProperties.put("hibernate.search.model_mapping", SearchMappingFactory.class.getCanonicalName());

I could pass instance of SearchMappingFactory with autowired bean inside but SearchMappingBuilder.getProgrammaticMappingClass does not allow that...

Was it helpful?

Solution

I found the solution, I made SearchMappingFactory a bean with autowired dependencies and passed searchMapping directly there:

 hibernateProperties.put("hibernate.search.model_mapping", searchMappingFactory.getSearchMapping());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top