Hibernate4.3.8 problems encountered during the integration of struts2, struts2 integrates hibernate
1. Exceptions:
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 (effecactserviceregistryimpl. 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. buildsetfactory (SettingsFactory. java: 295)
At org. hibernate. cfg. Configuration. buildSettingsInternal (config. 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: cocould 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 (effecactserviceregistryimpl. 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
The reason is as follows:
1. the reason is that hibernate4.0 is in hibernate. cfg. xml configuration Level 2 Cache and hibernate3.3 are different, this example uses Hibernate-core.4.3.6.Final, in fact from 4.0 is different, level 2 Cache configuration comparison is as follows:
4.0 and above are configured as follows:
<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 The configuration is as follows:
<Property name = "hibernate. cache. use_second_level_cache"> true </property>
<Property name = "cache. provider_class"> org. hibernate. cache. EhCacheProvider </property>
2. packages to be imported by hibernate:
A. All packages under hibernate-release-4.3.8.Final \ lib \ required.
B. Package under hibernate-release-4.3.8.Final \ lib \ optional \ ehcache.
C. Mysql-connector-java-5.1.7-bin.jar
D. Slf4j-1.5.6 and slf4j-api-1.5.6.jar in slf4j-nop-1.5.6.jar