using Spring 5.0.6 and a custom LocalSessionFactoryBean for Hibernate 5, I'd like to register a Hibernate integrator progammatically. This needs to be done via BootstrapServiceRegistryBuilder#applyIntegrator.
In the LocalSessionFactory bean, BootstrapServiceRegistryBuilder is only aquired in getMetadataSources():
This means, in order to simply apply an integrator, I have to override getMetadataSources to apply additional stuff to the BootstrapServiceRegistryBuilder. As private fields are used (metadataSourcesAccessed, metadataSources), ugly code duplication needs to be done.
So IMHO it would be great if the builder could easily be accessed in another way.
#20852 Support Hibernate 5.3's ManagedBeanRegistry for dependency injection
#21581 Hibernate 5: restore ability to inject "cacheRegionFactory" of LocalSessionFactoryBean
You could externally build the MetadataSources instance through a custom BootstrapServiceRegistryBuilder and set it through LocalSessionFactoryBean.setMetadataSources, getting your Integrator applied that way. You would do it the same way on a plain LocalSessionFactoryBuilder in a purely programmatic style, whereas it isn't quite as natural on LocalSessionFactoryBean which is meant for a more declarative style.
That said, this is not really obvious. It may make sense to provide a dedicated setIntegrators method on LocalSessionFactoryBean since this is by far the main purpose for customizing the BootstrapServiceRegistryBuilder. I'd rather keep the builder itself internal, not exposing other options or API dependencies through it.