1.在hibernate.cfg.xml
<!-- 启用session的线程本地化技术,将session绑定到当前的线程,实现session的传播(service层面上实现事务管理) -->
<property name="current_session_context_class">thread</property>
2.dao代码.
不用sf.openSession();
使用sf.getCurrentSession();
<!-- 启用session的线程本地化技术,将session绑定到当前的线程,实现session的传播(service层面上实现事务管理) -->
<property name="current_session_context_class">thread</property>
2.dao代码.
不用sf.openSession();
使用sf.getCurrentSession();