Java Hibernate 5.4.25二级缓存和扩展SingleToneCacheRegionFactory类
,可以将hibernate配置选项Java Hibernate 5.4.25二级缓存和扩展SingleToneCacheRegionFactory类,java,spring,hibernate,ehcache,ehcache-2,Java,Spring,Hibernate,Ehcache,Ehcache 2,,可以将hibernate配置选项hibernate.cache.region.factory\u class设置为类值。这允许我扩展类org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory,并为集群应用程序实现所需的额外代码。然后,可以将这个实现的类引用为hibernate设置中的hibernate.cache.region.factory\u类的配置值 spring-config.xml中的示例: <prop key=&quo
hibernate.cache.region.factory\u class
设置为类值。这允许我扩展类org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
,并为集群应用程序实现所需的额外代码。然后,可以将这个实现的类引用为hibernate设置中的hibernate.cache.region.factory\u类的配置值
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>
我现在正试图升级到5.4.25版本,但是SingletoneCacheRegionFactory被移动到一个内部类,代码被修改
最重要的是,hibernate.cache.region.factory\u类
config现在希望该类使用。这一点在报告中有所说明
例如:
<prop key="hibernate.cache.region.factory_class">ehcache-singleton</prop>
任何对以上内容的了解都将不胜感激 我认为应该扩展org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory
类,但新类与org.hibernate.cache.ehcache.SingletonEhcacheRegionFactory
略有不同,因此需要重写当前代码
如果您尝试扩展net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
,您将面临以下问题
关于如何引用它,它正在实现org.hibernate.boot.registry.selector.StrategyRegistrationProvider
接口,如:
package my.package.MyStrategyRegistrationProviderImpl;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.cache.spi.RegionFactory;
/**
* Makes the 1 contained region factory implementations available to the Hibernate
* {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service.
*/
public class MyStrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>( 1 );
strategyRegistrations.add(
new SimpleStrategyRegistrationImpl(
RegionFactory.class,
CustomSingletonEhCacheRegionFactory.class,
"custom-ehcache-singleton",
CustomSingletonEhCacheRegionFactory.class.getName(),
CustomSingletonEhCacheRegionFactory.class.getSimpleName(),
// legacy impl class name
"org.hibernate.cache.SingletonEhCacheRegionFactory",
"org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"
)
);
return strategyRegistrations;
}
}
非常感谢。这似乎解决了我的问题。我能够在我的spring-config.xml文件中使用“custom-ehcache singleton”
。所以定制ehcache单例
。我的部分实现需要一些其他更改,特别是来自CacheImpl的更改。请参阅:。
<prop key="hibernate.cache.region.factory_class">myEhcache-singleton</prop>
package my.package.MyStrategyRegistrationProviderImpl;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.cache.spi.RegionFactory;
/**
* Makes the 1 contained region factory implementations available to the Hibernate
* {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service.
*/
public class MyStrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>( 1 );
strategyRegistrations.add(
new SimpleStrategyRegistrationImpl(
RegionFactory.class,
CustomSingletonEhCacheRegionFactory.class,
"custom-ehcache-singleton",
CustomSingletonEhCacheRegionFactory.class.getName(),
CustomSingletonEhCacheRegionFactory.class.getSimpleName(),
// legacy impl class name
"org.hibernate.cache.SingletonEhCacheRegionFactory",
"org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"
)
);
return strategyRegistrations;
}
}
#
# Hibernate, Relational Persistence for Idiomatic Java
#
# License: GNU Lesser General Public License (LGPL), version 2.1 or later
# See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
#
#
# Hibernate, Relational Persistence for Idiomatic Java
#
# License: GNU Lesser General Public License (LGPL), version 2.1 or later
# See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
my.package.MyStrategyRegistrationProviderImpl