繁体   English   中英

没有会话时,Spring Hibernate getCurrentSession()?

[英]Spring Hibernate getCurrentSession() when there's no session?

标题中的所有内容我都对如何使用sessionFactory.getCurrentSession()感到困惑。

在我的Web应用程序中,创建了多线程以将消息保存到DB中,并且在创建每个线程时,我从未使用过openSession()方法,所有Daos使用getCurrentSession() 到目前为止,一切正常。

而且没有配置CurrentSessionContext 那么休眠是否会为此线程生成一个新的会话,如果不是,那么getCurrentSession work如何getCurrentSession work

更新

是的,我正在使用Spring 3.1。

Tomcat6(作为Eclipse中的插件和Linux机器上的真实服务器,该应用程序可在两个服务器上运行)

Spring HibernateTransactionManager将当前会话绑定到活动事务,从而允许getCurrentSession()返回与正在进行的Spring事务关联的会话:

单个Hibernate SessionFactory的PlatformTransactionManager实现。 将一个Hibernate Session从指定的工厂绑定到线程,可能允许每个工厂一个线程绑定的Session。 Hibernate访问代码需要SessionFactory.getCurrentSession()来支持此事务处理机制,并且SessionFactory是使用SpringSessionContext配置的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM