文档介绍:错误1:解决HIbernate3运行出现No CurrentSessionContext configured!错误
是由于函数getcurrentsession()造成的,可以将其改为opensession(),也可以进行一下修改:
修改配置文件:
根据运行环境添加如下配置:
1)在容器中运行即在集成环境下(例如Jboss),-factory段加入:
<property name="current_session_context_class">jta</property>
2) 独立运行:即在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),-factory段加入:()
<property name="current_session_context_class">thread</property>
注::先“property”,然后是“mapping”,以上内容是“property”,应在“mapping”之上。
  错误2:hibernate3, No TransactionManagerLookup specified
Session session=()
而不是:
Session session=()
 openSession()与getCurrentSession()区别:
,而openSession不会。
2. getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSession必须手动关闭。
这里getCurrentSession本地事务(本地事务:jdbc)时要在配置文件里进行如下设置
* 如果使用的是本地事务(jdbc事务)
<property name="">thread</property>
* 如果使用的是全局事务(jta事务)
<property name="">jta</property>
() 使用当前的session,openSession() 重新建立一个新的session
,如果DAO 层使用Spring 的hibernate 模板,通过Spring 来控制session 的生命周期,则首选getCurrentSession ()。
SessionFactory 启动的时候, Hibernate 会根据配置创建相应的 CurrentSessionContext ,在 getCurrentSession() 被调用的时候,实际被执行的方法是