你的位置:首页 > Java教程

[Java教程]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.

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