org.hibernate.HibernateException: No CurrentSessionContext configured!
没有currentSession配置错误,即在我们使用currentSession的时候要在hibernate.cfg.xml中进行相关的事务配置:
1、本地事务
<property name="hibernate.current_session_context_class">thread</property>
2、全局事务
<property name="hibernate.current_session_context_class">jta</property>
这样就解决了!
如果在获得session 对象时使用的是 session = sessionFactory.getCurrentSession();
则此处可以改成 session = sessionFactory.openSession();
这样就不用修改上面的配置文件了

本文详细解释了在使用Hibernate框架时遇到'NoCurrentSessionContextconfigured!'错误的原因及解决方法,包括本地事务和全局事务两种配置方式。同时,提供了解决问题的替代方案,避免修改配置文件。
16万+

被折叠的 条评论
为什么被折叠?



