在使用Hibernate4做二级缓存的测试(HashtableCacheProvider)时,会报如下异常:
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.hibernate.service.internal.AbstractServiceRegistryI
mpl.createService(AbstractServiceRegistryI
mpl.java:186)
at org.hibernate.service.internal.AbstractServiceRegistryI
mpl.initializeService(AbstractServiceRegistryI
mpl.java:150)
at org.hibernate.service.internal.AbstractServiceRegistryI
mpl.getService(AbstractServiceRegistryI
mpl.java:131)
at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:262)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1746)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)
at action.QueryCache.main(QueryCache.java:19)
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvai
lableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given, please either disable second level cache or set correct region factory class name to property hibernate.cache.region.factory_class (and make sure the second level cache provider, hibernate-infinispan, for example, is available in the classpath).
at org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:87)
at org.hibernate.cache.spi.UpdateTime
stampsCache.(UpdateTimestampsCache.java:63)
at org.hibernate.internal.CacheImpl.(CacheImpl.java:72)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
at org.hibernate.service.internal.SessionFactoryServiceReg
istryImpl.initiateService(SessionFactoryServiceReg
istryImpl.java:91)
at org.hibernate.service.internal.AbstractServiceRegistryI
mpl.createService(AbstractServiceRegistryI
mpl.java:176)
... 6 more
Exception in thread "main" java.lang.NullPointerException
at action.QueryCache.main(QueryCache.java:25)
主要原因有下:
1.
2.在org.hibernate.cache包下面缺少很多class文件,如HashtableCacheProvider.class等,你可以将hibernate3中org.hibernate.cache下面的文件拷贝到hibernate4的核心j ar包下,或者使用Hibernate3的核心jar包。
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvai
Exception in thread "main" java.lang.NullPointerException
主要原因有下:
1.
![Unable <wbr>to <wbr>create <wbr>requested <wbr>service <wbr>[org.hibernate.engine.spi.CacheImple Unable <wbr>to <wbr>create <wbr>requested <wbr>service <wbr>[org.hibernate.engine.spi.CacheImple](https://i-blog.csdnimg.cn/blog_migrate/cfe4ac87721866e19e2e759be736e6dd.jpeg)
2.在org.hibernate.cache包下面缺少很多class文件,如HashtableCacheProvider.class等,你可以将hibernate3中org.hibernate.cache下面的文件拷贝到hibernate4的核心j ar包下,或者使用Hibernate3的核心jar包。