Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Hibernate Integrator through LocalSessionFactoryBean [SPR-16828] #21368

Closed
spring-projects-issues opened this issue May 16, 2018 · 3 comments
Closed
Assignees
Labels
in: data type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented May 16, 2018

Niko Wittenbeck opened SPR-16828 and commented

Hi there,

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():

public MetadataSources getMetadataSources() {
(...)
 BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
(...)
 this.metadataSources = new MetadataSources(builder.build());
 }
 return this.metadataSources;
 }

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.


Affects: 5.0.6

Issue Links:

  • #20852 Support Hibernate 5.3's ManagedBeanRegistry for dependency injection
  • #21581 Hibernate 5: restore ability to inject "cacheRegionFactory" of LocalSessionFactoryBean

Referenced from: commits b6d9556

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 26, 2018

Juergen Hoeller commented

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.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 28, 2018

Niko Wittenbeck commented

Thanks for the clarification and the advise, your recommended approach is perfectly fine.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 28, 2018

Juergen Hoeller commented

I've added this as a "hibernateIntegrators" property a.k.a. setHibernateIntegrators on LocalSessionFactoryBean to master now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants