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

来源:互联网 发布:戏曲分类知乎 编辑:程序博客网 时间:2024/05/20 10:13

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>

重新运行一下就好了


0 0