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

Hibernate 5: restore ability to inject "cacheRegionFactory" of LocalSessionFactoryBean [SPR-17043] #21581

Closed
spring-projects-issues opened this issue Jul 15, 2018 · 2 comments
Assignees
Labels
in: data type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 15, 2018

Taras Tielkes opened SPR-17043 and commented

Spring provided a convenience property for "cacheRegionFactory" in the Hibernate 3.x and 4.x packages. The current support for Hibernate 5.x no longer provides this flexibility. This is quite unfortunate, as there are some scenarios where customization of the underlying cache infrastructure is desired, and injection of various Spring-managed dependencies is the natural approach.

Please note that the "hibernate.cache.region.factory_class" property is somewhat misleading: in addition to an implementation class, an actual object instance implementing org.hibernate.cache.spi.RegionFactory is equally valid: please see org.hibernate.cache.internal.RegionFactoryInitiator#initiateService.

At the moment we are using Hibernate 5.1.x, and I have not verified that the approach described below is equally applicable to 5.0.x/5.1.x/5.2.x/5.3.x APIs.

That said, the current workaround I am using is to subclass the hibernate5 LocalSessionFactoryBean as follows:

public class MyLocalSessionFactoryBean extends LocalSessionFactoryBean {

    private RegionFactory regionFactory;

    @Required
    public void setRegionFactory(RegionFactory regionFactory) {
        this.regionFactory = regionFactory;
    }

    @Override
    protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) {
        sfb.getProperties().put(AvailableSettings.CACHE_REGION_FACTORY, regionFactory);
        return sfb.buildSessionFactory();
    }
}

(inspired by org.springframework.orm.hibernate5.LocalSessionFactoryBuilder#setMultiTenantConnectionProvider)

If possible (across the range of Hibernate versions currently supported by Spring), it would be nice to have the "cacheRegionFactory" restored for 5.1. A backport to 5.0.x would be a bonus :)


Affects: 4.3.18, 5.0.7

Issue Links:

  • #20852 Support Hibernate 5.3's ManagedBeanRegistry for dependency injection
  • #15683 Impossible to customise Hibernate RegionFactory
  • #21368 Apply Hibernate Integrator through LocalSessionFactoryBean

Referenced from: commits 93d9121

@spring-projects-issues
Copy link
Collaborator Author

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

Juergen Hoeller commented

I've added a corresponding setCacheRegionFactory setter to LocalSessionFactoryBean as well as LocalSessionFactoryBuilder, going nicely with other recent additions such as setIntegrators and setBeanContainer. I prefer keeping this 5.1 only since there are quite a few related additions in that release, and there are easy enough workarounds for the time being.

@spring-projects-issues
Copy link
Collaborator Author

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

Taras Tielkes commented

Fair enough, thanks for the quick fix. Looking forward to 5.1, also for the integrators support.

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