Skip to content

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

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

Closed
spring-projects-issues opened this issue Nov 1, 2013 · 6 comments
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 1, 2013

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

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

Taras Tielkes commented

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 15, 2018

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
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants