Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!

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>

重新運行一下就好了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章