Hibernate使用缓存查询时报错:
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1012)
at com.mao.secondCache.NewManager.secondCacheTest(NewManager.java:44)
at com.mao.secondCache.NewManager.main(NewManager.java:39)
解决方案:
在hibernate.cfg.xnl中添加如下代码:
<!-- 指定根据当前线程来界定上下文相关Session -->
<property name="hibernate.current_session_context_class">thread</property>
重新运行一下就好了