- HibernateException: No CurrentSessionContext configured!
1、在 SessionFactory(会话工厂)启动的时候,Hibernate 会根据配置创建相应的 CurrentSessionContext,
在getCurrentSession()被调用的时候,实际被执行的方法是 CurrentSessionContext.currentSession()。
2、这里的“根据配置”就是如下配置:
* 如果使用的是本地事务(jdbc事务 本地事务:数据库只有一个)
<property name="hibernate.current_session_context_class">thread</property>
* 如果使用的是全局事务(jta事务 全局事务:数据库有多个)
<property name="hibernate.current_session_context_class">jta</property>
所以解决问题的办法就是根据需求在hibernate.cfg.xml文件中加上上边的配置即可!
原文链接:https://blog.csdn.net/xlgen157387/article/details/39801771