You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Apply Hibernate Integrator through LocalSessionFactoryBean [SPR-16828] #21368
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.
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.
Activity
spring-projects-issues commentedon Jun 26, 2018
Juergen Hoeller commented
You could externally build the
MetadataSourcesinstance through a customBootstrapServiceRegistryBuilderand set it throughLocalSessionFactoryBean.setMetadataSources, getting yourIntegratorapplied that way. You would do it the same way on a plainLocalSessionFactoryBuilderin a purely programmatic style, whereas it isn't quite as natural onLocalSessionFactoryBeanwhich is meant for a more declarative style.That said, this is not really obvious. It may make sense to provide a dedicated
setIntegratorsmethod onLocalSessionFactoryBeansince this is by far the main purpose for customizing theBootstrapServiceRegistryBuilder. I'd rather keep the builder itself internal, not exposing other options or API dependencies through it.spring-projects-issues commentedon Jun 28, 2018
Niko Wittenbeck commented
Thanks for the clarification and the advise, your recommended approach is perfectly fine.
spring-projects-issues commentedon Jun 28, 2018
Juergen Hoeller commented
I've added this as a "hibernateIntegrators" property a.k.a.
setHibernateIntegratorsonLocalSessionFactoryBeanto master now.