简体   繁体   English

Hibernate4,Spring4.3,线程,会话

[英]Hibernate4, Spring4.3, Thread, Session

i have the following declared in spring.xml: 我在spring.xml中声明了以下内容:

 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
  ...
  </bean>
  <bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
  </bean>

    <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <!-- Adapters -->
    <bean id="ADBAdapter" class="model.adapter.ADBAdapter">
        <constructor-arg>
            <ref bean="sessionFactory" />
        </constructor-arg>
    </bean>

So after i created the context. 因此,在创建上下文之后。 I can Access my ADBAdapter and do stuff. 我可以访问我的ADBAdapter并执行操作。

The Problem is, that i want to use ADBAdapter in another Thread. 问题是,我想在另一个线程中使用ADBAdapter。 But then i get sometimes a SessionClosed Exception, because the session gets closed in the parent thread. 但是后来我有时会收到SessionClosed异常,因为会话在父线程中关闭了。

How can I handle this ? 我该如何处理?

Thank you for your help 谢谢您的帮助

在休眠状态下,您可以使用

hibernate.current_session_context_class=thread 

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

相关问题 当前线程的事务同步会话Hibernate4异常spring 4 - transaction-synchronized Session for current thread Hibernate4 Exception spring 4 将Spring 3.1项目更新为hibernate4,现在找不到当前线程的会话 - Updated Spring 3.1 project to hibernate4 now getting No Session found for current thread Spring JPA hibernate4拦截器 - Spring JPA hibernate4 interceptor 春季+ Hibernate4 + JTA + JBossTS - Spring + Hibernate4 + JTA + JBossTS 具有Hibernate4的Spring4在独立进程中失败 - Spring4 with Hibernate4 fails in standalone process Spring 4.3 -&gt; 5.3 和 Hibernate 3.6 -&gt; 5.4 升级导致错误:无法获取当前线程的事务同步 Session - Spring 4.3 -> 5.3 and Hibernate 3.6 -> 5.4 upgrade results in error: Could not obtain transaction-synchronized Session for current thread TomCat EE-Hibernate4和Spring4:会话工厂ClassNotFoundException:javax.persistence.NamedStoredProcedureQuery - TomCat EE - Hibernate4 & Spring4: Session Factory ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery 带注释的Spring + Hibernate:没有Hibernate会话绑定到线程 - Spring + Hibernate with annotations: No Hibernate Session bound to thread Spring Batch的元表不是由Hibernate4创建的 - Meta tables for Spring Batch not created by Hibernate4 Spring + Hibernate:没有Hibernate Session绑定到线程 - Spring + Hibernate: No Hibernate Session bound to thread
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM