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>
重新運行一下就好了