初學(xué)hibernate,出現(xiàn)No CurrentSessionContext configured錯(cuò)誤,檢查了幾次配置都沒有發(fā)現(xiàn)問題,最后上網(wǎng)查找發(fā)現(xiàn)是配置文件的問題
解決如下:
在集成Hibernate的環(huán)境下(例如Jboss),在hibernate.cfg.xml中session-factory段加入:
<property name="current_session_context_class">jta</property>
在不集成Hibernate的環(huán)境下(例如使用JDBC的獨(dú)立應(yīng)用程序),在hibernate.cfg.xml中session-factory段加入:
<property name="current_session_context_class">thread</property>