hibernate4.3.8整合struts2过程中遇到的问题
1.遇到的异常:
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:261)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2444)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2440)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
at com.ad.model.StudentTest.main(StudentTest.java:41)
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:105)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251)
... 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
原因如下:
1.原因在于hibernate4.0在hibernate.cfg.xml配置二级缓存和hibernate3.3有所不同,本例子用的是 Hibernate-core.4.3.6.Final,实际上从4.0开始就不一样,二级缓存的配置对比如下所示:
4.0以上配置如下:
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
3.3配置如下:
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="cache.provider_class ">org.hibernate.cache.EhCacheProvider</property>
2.hibernate需要导入的包:
a。hibernate-release-4.3.8.Final\lib\required下面的所有包。
b。hibernate-release-4.3.8.Final\lib\optional\ehcache下面的包。
c。mysql-connector-java-5.1.7-bin.jar
d。slf4j-1.5.6中的slf4j-api-1.5.6.jar和slf4j-nop-1.5.6.jar
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。