0

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

  • Finally the problem was, that i passed Hibernate Entities through Thread bounds. I solved the problem, by passing only the Oid(primary key) and load it again in the Thread itself. – Julian Rost Aug 06 '18 at 08:29

1 Answers1

0

In hibernate you can use

hibernate.current_session_context_class=thread 
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Daniel Jipa
  • 878
  • 11
  • 24
  • In this Thread they say its not recommend like this https://stackoverflow.com/questions/18832889/spring-transactions-and-hibernate-current-session-context-class – Julian Rost May 14 '18 at 19:04