配置hibernate 二级缓存总是出问题
配置hibernate 二级缓存总是出问题:
Exception in thread "main"
java.lang.ExceptionInInitializerError at com.linhao.hibernate.CacheTest.addUser(CacheTest.java:25)
at com.linhao.hibernate.CacheTest.main(CacheTest.java:13)
Caused by:
org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:68)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:339)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
at com.linhao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:20)
... 2 more
该配的都配了, 该加的包都加了。
------解决方案--------------------
1、Exception in thread "main" java.lang.
ExceptionInInitializerError空指针异常 引起main函数不能运行 ,看看是否有没被实例化的,没有具体代码也不是很清楚。
2、org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage... ...
是没有二级缓存jar的问题 <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
这个配置一下就ok了,
再不行的话直接把二级缓存和查询缓存禁用了ok了