You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Impossible to customise Hibernate RegionFactory [SPR-11056] #15683
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.
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.
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.
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.
Activity
spring-projects-issues commentedon Nov 1, 2013
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 commentedon Nov 1, 2013
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 commentedon Nov 15, 2013
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 commentedon Jul 15, 2018
Taras Tielkes commented
Juergen, what's the reason this feature was dropped from the Hibernate 5 LocalSessionFactoryBean?
spring-projects-issues commentedon Jul 15, 2018
Juergen Hoeller commented
The previous implementation style didn't work since the Hibernate
Settingsclass 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 theServiceRegistry, as suggested in https://stackoverflow.com/questions/39085529/how-to-inject-spring-managed-cacheregionfactory-in-spring-hibernate-5-localsessi ... This is quite natural withLocalSessionFactoryBuilderbut not ideal withLocalSessionFactoryBean, 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 commentedon 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