本帖最后由 纯情小飞飞 于 2017-10-5 22:07 编辑
请问下飞哥关于Hibernate绑定session到当前线程的原理,为什么写thread?
在hibernate.cfg.xml中要这样配置,才能获取当前线程的Session
- <property name="hibernate.current_session_context_class">thread</property>
配置完成之后,这个才生效:
- /**
- * 把session对象绑定到当前线程里
- * @return
- */
- public static Session getCurrentSession(){
- return sessionFactory.getCurrentSession();
- }
麻烦飞哥解释下,非常感谢。
|