【发布时间】:2013-12-21 13:38:07
【问题描述】:
我已阅读与此相关的帖子,但没有得到任何适合我的答案。
我在Hibernate v4.3. 中配置second level cache 并且我使用了MySQL 5.0
我在hibernate.cfg.xml中写了以下元素
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
我已经为缓存注释了我的实体类,如下所示
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Employee { ....}
运行时出现以下异常
INFO: HHH000397: Using ASTQueryTranslatorFactory Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:233) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2442) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2438) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1855) at com.example.hibernate.Hibernate4Main.main(Hibernate4Main.java:32) Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.ehcache.EhCacheRegionFactory] at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:101) at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:46) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:83) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223) ... 7 more Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.ehcache.EhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory] at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:128) at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:87) ... 10 more
我看到Hibernate v3 有不同的缓存提供程序,例如EhCacheProvoider。所有都在org.hibernate.cache 包中。
但是对于Hibernate 4.3,只有 3 个类为 RegionFactory.class,另外两个属于 exception。
1.上面的代码有什么问题?
2。 Hibernate 4.3 中二级缓存配置的主要变化是什么?
【问题讨论】:
-
你好。我有同样的问题。你有没有找到解决这个问题的方法?
标签: java hibernate second-level-cache