Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果存在';没有会议吗?_Java_Spring_Hibernate - Fatal编程技术网

Java 如果存在';没有会议吗?

Java 如果存在';没有会议吗?,java,spring,hibernate,Java,Spring,Hibernate,标题中的所有内容 我不知道如何使用sessionFactory.getCurrentSession() 在我的web应用程序中,创建了多个线程以在DB中保存消息,在创建每个线程时,我从未使用过openSession()方法,所有dao都使用getCurrentSession()。到目前为止,它运行良好 并且没有配置CurrentSessionContext。那么hibernate是否会为此线程生成新会话,如果不是的话,这个getCurrentSession如何工作 更新 是的,我用的是Sprin

标题中的所有内容 我不知道如何使用
sessionFactory.getCurrentSession()

在我的web应用程序中,创建了多个线程以在DB中保存消息,在创建每个线程时,我从未使用过
openSession()
方法,所有
dao
都使用
getCurrentSession()
。到目前为止,它运行良好

并且没有配置
CurrentSessionContext
。那么hibernate是否会为此线程生成新会话,如果不是的话,这个
getCurrentSession如何工作

更新

是的,我用的是Spring3.1

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

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

针对单个Hibernate SessionFactory的PlatformTransactionManager实现。将指定工厂的Hibernate会话绑定到线程,可能允许每个工厂有一个线程绑定会话。需要支持此事务处理机制的Hibernate访问代码需要SessionFactory.getCurrentSession(),SessionFactory配置为SpringSessionContext


你需要告诉我们更多关于上下文的信息。您的应用程序是否在JavaEE应用程序服务器中运行?您正在使用Spring吗?@JBNizet是否需要更多信息?因此,这意味着无论是否调用某些DAO操作,只要创建了新的
线程
,新的
会话
都会自动绑定到它?我如何调试这个?在哪里可以监视此
会话
对象?否。事务开始时,事务管理器将会话绑定到线程。