初學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>