In Hibernate 5.2.18, it was possible to set the hibernate configuration option hibernate.cache.region.factory_class
to a class value. This allowed me to extend the class org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
and implement required extra code for my clustered application. This implemented class could then be referenced as the config value for the hibernate.cache.region.factory_class
config in the hibernate settings.
Example in spring-config.xml:
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">com.example.MySingletonEhCacheRegionFactory</prop>
Implemented class:
public class MySingletonEhCacheRegionFactory extends
SingletonEhCacheRegionFactory {
// Implementation
}
I am now trying to upgrade to version 5.4.25, however in version 5.3.0 the SingletonEhCacheRegionFactory was moved to an internal class and the code was altered.
On top of this, the hibernate.cache.region.factory_class
config now expects the shortened name for the class. This is stated in the Hibernate 5.4 documentation.
Example:
<prop key="hibernate.cache.region.factory_class">ehcache-singleton</prop>
So my questions are:
Firstly, is it still possible to extend the SingletonEhcacheRegionFactory
class from the new location org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory
and add my custom implementation as a shortened value to the hibernate configuration?
Or should I be extending the net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
class instead? It used to be recommended to use the other class over this (see here) but it says nothing about version 5+.
For Hibernate 4, use org.hibernate.cache.ehcache.EhCacheRegionFactory instead of net.sf.ehcache.hibernate.EhCacheRegionFactory.
Secondly, can we reference our own class in the hibernate config using the shortened name?
<prop key="hibernate.cache.region.factory_class">myEhcache-singleton</prop>
Any insight into the above is appreciated!
I think you should extent the
org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory
class, but the new one is slightly different from theorg.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
so you will need to rewrite your current code.If you try to extent
net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
you will face some problems like SingletonEhCacheRegionFactory is no longer available when upgrading from Hibernate 5.2 to 5.3About how to reference it, it is implementing
org.hibernate.boot.registry.selector.StrategyRegistrationProvider
interface, like:and creating a file called:
META-INF/services/org.hibernate.boot.registry.selector.StrategyRegistrationProvider
with the full class name: