解决HIbernate3运行出现No CurrentSessionContext configured!错误

来源:互联网 发布:在线订单提交系统源码 编辑:程序博客网 时间:2024/05/13 20:57

 

 解决HIbernate3运行出现No CurrentSessionContext configured!错误

是由于函数getcurrentsession()造成的,可以将其改为opensession(),也可以进行一下修改:

修改配置文件:hibernate.cfg.xml

根据运行环境添加如下配置:

1)在容器中运行即在集成环境下(例如Jboss),在hibernate.cfg.xml中session-factory段加入:

<property name="current_session_context_class">jta</property>

2) 独立运行:即在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),在hibernate.cfg.xml中session-factory段加入:(myeclipse6.0)

<property name="current_session_context_class">thread</property>

注:hibernate.cfg.xml文件中内容的编写是有顺序的:先“property”,然后是“mapping”,以上内容是“property”,应在“mapping”之上。