-
Notifications
You must be signed in to change notification settings - Fork 38.5k
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
Comments
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 |
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 |
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 |
Taras Tielkes commented Juergen, what's the reason this feature was dropped from the Hibernate 5 LocalSessionFactoryBean? |
Juergen Hoeller commented The previous implementation style didn't work since the Hibernate |
Taras Tielkes commented Juergen, I think there is an easier approach that does not require |
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
The text was updated successfully, but these errors were encountered: