Skip to content

Impossible to customise Hibernate RegionFactory [SPR-11056] #15683

Closed

Description

@spring-projects-issues

nigel magnay opened SPR-11056 and commented

This is really painful.

If you want to create Hibernate Session Factories with a cache object (and not through a brain-damaged class-name property string - you know, because it might be a bean with @Inject dependencies), it's impossible to do so.

What you'd like to be able to do some sort of customisation of the Configuration through LocalSessionFactoryBuilder. E.g:

class MyLocalSessionFactoryBuilder extends LocalSessionFactoryBuilder {

@Override
public Settings buildSettings(ServiceRegistry serviceRegistry) {

Settings settings = super.buildSettings(serviceRegistry);
settings.setRegionFactory ( /* whatever I like */
// possibly other settings

return settings;
}

Sounds good. But LocalSessionFactoryBean itself is manufactured, in one class only, in line LocalSessionFactoryBean:277.

Overriding 372 looks promising :
protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) {
return sfb.buildSessionFactory();
}

But by this point it's too late. I can't even override afterPropertiesSet, as every member varible is private rather than protected.

All I can do is clone the entire class, simply to create a different subclass in Line 278.

If this were configurable (I.E: the localsessionfactorybuilder was a property that could be passed in) this would be way more usable.


Affects: 3.2.4

Issue Links:

Referenced from: commits 00474ce

Activity

  1. spring-projects-issues commented on Nov 1, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Is there anything specific beyond the RegionFactory that you'd commonly like to set? We're still missing some of the direct setters that we had in the Hibernate 3 variant, so it'd be great to make the Hibernate 4 LocalSessionFactoryBean with its top-level setters as complete as possible.

    Custom access to the Settings would be nice as well, of course. I'll see what we can do there.

    Juergen

  2. spring-projects-issues commented on Nov 1, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Note that, at least on Hibernate 4.2, most of the setter methods on Settings - including setRegionFactory - aren't public. So it doesn't seem to be suggested to actually customize those. We can call setRegionFactory reflectively for direct RegionFactory support in our LocalSessionFactoryBean, but it doesn't seem to be feasible to expose the buildSettings method directly.

    Generally speaking, it'd be great if Hibernate was more instance-oriented in its configuration style. For some reason, they were quite class name based in Hibernate 3, and they still are for many customization purposes in Hibernate 4. There's only so much we can do to work around this, I'm afraid.

    Juergen

  3. spring-projects-issues commented on Nov 15, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've added setCacheRegionFactory support to LocalSessionFactoryBuilder and LocalSessionFactoryBean two weeks ago, and will leave it at that for the time being since the Hibernate Settings API doesn't seem to be meant for public use.

    Juergen

  4. spring-projects-issues commented on Jul 15, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Taras Tielkes commented

    Juergen, what's the reason this feature was dropped from the Hibernate 5 LocalSessionFactoryBean?

  5. spring-projects-issues commented on Jul 15, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    The previous implementation style didn't work since the Hibernate Settings class doesn't have any such setters anymore (they weren't public before either but at least they were there). As of Hibernate 5, it all has to happen via the ServiceRegistry, as suggested in https://stackoverflow.com/questions/39085529/how-to-inject-spring-managed-cacheregionfactory-in-spring-hibernate-5-localsessi ... This is quite natural with LocalSessionFactoryBuilder but not ideal with LocalSessionFactoryBean, so we could consider adding a corresponding setter method out-of-the-box again. Please create a new JIRA ticket for it, I'll look at it ASAP.

  6. spring-projects-issues commented on Jul 15, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Taras Tielkes commented

    Juergen, I think there is an easier approach that does not require ServiceRegistry. Per your request, a new Jira ticket: #21581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions