4

I am using:

  • Hibernate 5.0.2
  • Spring 4.2
  • Atomikos 3.9.3

The official documentation says you only have to set the jtaTransactionManager, and everything works:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <property name="dataSource" ref="atomikosDataSource" />
            <property name="jtaTransactionManager" ref="jtaTransactionManager"/>
            [...]
    </bean>

Unfortuntely, the session is not flushed - no writes are taking place. What is the issue?

Bacteria
  • 8,406
  • 10
  • 50
  • 67
Michael Böckling
  • 7,341
  • 6
  • 55
  • 76

1 Answers1

6

The problem is that Hibernate 5 requires us to set the following property, which Spring doesn't do automatically yet:

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    [...]
    <property name="hibernateProperties">
        <props>
            [...]
            <prop key="hibernate.transaction.coordinator_class">jta</prop>
        </props>

This fixed the issue for me.

Michael Böckling
  • 7,341
  • 6
  • 55
  • 76
  • 1
    I had a different issue. Session was being flushed but the connection was never released. Setting this property resolved my connection leakage issue. – Jason B Feb 29 '16 at 23:24
  • 1
    What is jta value in coordinator class. are we not required to define the factory_class anymore – swingmicro Jun 21 '16 at 04:37
  • Just wanted to give credit to Jason B for his comment above and perhaps add some search words to help other users who have a problem of losing conenctions... We had a problem of losing conenctions. We ran a job that rapidly obtained conenctions and did not release the connections. We tried several ways of configuration until i hit Jason's comment above and that solved our issue. – inor Apr 12 '17 at 13:28
  • This did it for me. Thank you kind stranger! – Iuliana Cosmina May 28 '17 at 07:16