"No CurrentSessionContext configured"错误

 

用Hibernate开发遇到"No CurrentSessionContextconfigured"错误

 

 

在使用SessionFactory的getCurrentSession方法时遇到如下错误,经过检查,原因如下:

是因为在hibernate.cfg.xml文件中忘记进行了如下设置:hibernate.current_session_context_class

如果是在web容器中运行hibernate,则在hibernate.cfg.xml中加入这句话:

<propertyname="hibernate.current_session_context_class">jta</property>


如果是在一个单独的需要进行JDBC连接的javaapplication中运行hibernate,则这样设置:

<propertyname="hibernate.current_session_context_class">thread</property>


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章