今天在测试的时候遇到了org.hibernate.HibernateException: No CurrentSessionContext configured!错误。。。找了半天,在百度上才发现是什么原因。。。
初学hibernate,出现No CurrentSessionContext configured错误,检查了几次配置都没有发现问题,最后上网查找发现是配置文件的问题
解决如下:
在集成Hibernate的环境下(例如Jboss),在hibernate.cfg.xml中session-factory段加入:
<property name="current_session_context_class">jta</property>
在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),在hibernate.cfg.xml中session-factory段加入:
<property name="current_session_context_class">thread</property>
加入了这句话什么测试类就可以运行了。。。。哎,这个错误我来记录下
初学hibernate,出现No CurrentSessionContext configured错误,检查了几次配置都没有发现问题,最后上网查找发现是配置文件的问题
解决如下:
在集成Hibernate的环境下(例如Jboss),在hibernate.cfg.xml中session-factory段加入:
<property name="current_session_context_class">jta</property>
在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),在hibernate.cfg.xml中session-factory段加入:
<property name="current_session_context_class">thread</property>
加入了这句话什么测试类就可以运行了。。。。哎,这个错误我来记录下