简体   繁体   中英

Hibernate4, Spring4.3, Thread, Session

i have the following declared in 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.

The Problem is, that i want to use ADBAdapter in another Thread. But then i get sometimes a SessionClosed Exception, because the session gets closed in the parent thread.

How can I handle this ?

Thank you for your help

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

hibernate.current_session_context_class=thread 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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