Skip to content

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

Closed

Description

@spring-projects-issues

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:

Referenced from: commits b6d9556

Activity

  1. spring-projects-issues commented on Jun 26, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. spring-projects-issues commented on Jun 28, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Niko Wittenbeck commented

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

  3. spring-projects-issues commented on Jun 28, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

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

  4. added
    in: data
    type: enhancement
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions