Unable to create requested service [org.hibernate.engine.spi.CacheImple

在使用Hibernate4做二级缓存的测试(HashtableCacheProvider)时,会报如下异常:
org.hibernate.service.spi.ServiceException: Unable to createrequested service [org.hibernate.engine.spi.CacheImplementor]
 
   atorg.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)
    atorg.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
    atorg.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    atorg.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:262)
    atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1746)
    atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)
    ataction.QueryCache.main(QueryCache.java:19)
Caused by:org.hibernate.cache.NoCacheRegionFactoryAvailableException:Second-level cache is used in the application, but propertyhibernate.cache.region.factory_class is not given, please eitherdisable second level cache or set correct region factory class nameto property hibernate.cache.region.factory_class (and make sure thesecond level cache provider, hibernate-infinispan, for example, isavailable in the classpath).
    atorg.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:87)
    atorg.hibernate.cache.spi.UpdateTimestampsCache.(UpdateTimestampsCache.java:63)
    atorg.hibernate.internal.CacheImpl.(CacheImpl.java:72)
    atorg.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
    atorg.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
    atorg.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91)
    atorg.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)
    ... 6more
Exception in thread "main" java.lang.NullPointerException
    ataction.QueryCache.main(QueryCache.java:25)
主要原因有下:
1. Unable <wbr>to <wbr>create <wbr>requested <wbr>service <wbr>[org.hibernate.engine.spi.CacheImple
2.在org.hibernate.cache包下面缺少很多class文件,如HashtableCacheProvider.class等,你可以将hibernate3中org.hibernate.cache下面的文件拷贝到hibernate4的核心jar包下,或者使用Hibernate3的核心jar包。

猜你喜欢

转载自blog.csdn.net/jinghuayuanli/article/details/38587325
今日推荐