[英]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.