Multi-EntityManagerFactory programmatic mapping cause HSEARCH700027

Description

In some reason, I build two DataSource(memory and disk) and corresponding two LocalContainerEntityManagerFactoryBean, then I do something for alloting my Entities to them, every EMF have different entities. When I use @Indexed, application work correct; then I try using programmatic mapping, implements HibernateOrmSearchMappingConfigurer, it's cause

I found that because every EFM should call HibernateOrmSearchMappingConfigurer#configure once, so the Entity who at EFM disk can not found at EFM memory,
I hacked it:

I think my code is uglily, can supply some method to filter it?

Environment

SunJDK1.8.0_191 SpringBoot2.2.12.RELEASE Win10 HSQLDB2.5.1

Activity

Show:
Yoann Rodière
January 28, 2021, 11:57 PM

I’ve been trying to be cautious about exposing the internals, especially when, like here, it’s about exposing information that you already have: after all, you decide what the entities are.

Exposing the SessionFactory through the context may not be safe either, since at this point the session factory is not fully built.

Maybe we could solve that simply by using a different configurer in each session factory?

Depending on how you instantiate the entity manager factory, you may be able to set the property hibernate.search.mapping.configurer to an instance of HibernateOrmSearchMappingConfigurer that you created yourself, by calling the constructor directly, instead of the fully-qualified class name of your configurer. This would allow you to pass only the relevant type mappings to its constructor, instead of autowiring a global list of type mappings that may (or may not) be relevant. Can you try this?

lan zen
January 29, 2021, 12:19 AM

Thanks your reply, I just try set hibernate.search.mapping.configurer to specific EFM and comment this property from hibernate.properties

It’s work!

 

Thank you again!

Yoann Rodière
January 29, 2021, 12:27 AM

No problem! Feel free to drop by on our forums if you have other issues.

Won't Fix

Assignee

Yoann Rodière

Reporter

lan zen

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Affects versions

Priority

Minor