Kuppusamy
Kuppusamy

Reputation: 153

Transaction not getting committed

Working on a Spring 5 and Hibernate Project. Using Spring for bean management, transaction and MVC. The changes are not getting committed to database though i can see the insert statement in the log. There is no error. There is no issue with select statements. I could login into the application. Below are my configurations:

framework.xml:

    <context:component-scan base-package="com.test" > 
        <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> 
    </context:component-scan> 
    
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" 
          ref="dataSource"/>
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="jtaTransactionManager" ref="transactionManager" />
        
    </bean>
    <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
        <property name="forceShutdown" value="false" />
    </bean>
 
    <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
        <property name="transactionTimeout" value="300" />
    </bean>
    
     <!--  
    <bean id="HibernateTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    -->
      
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" >
    <property name="transactionManager"><ref bean="atomikosTransactionManager"  /></property>
    <property name="userTransaction"><ref bean="atomikosUserTransaction"  /></property>
    </bean>
     
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="false"/>
In the above configuration, i excluded the controllers as they are loaded using a different mvc related config files.

The service classes were annotated with @Transactional.

I tried without JTA with plain HibernateTransactionManager also. The transactions are not getting committed.
The below entry is also for hibernate to use JTA as transaction manager
hibernate.transaction.jta.platform to org.hibernate.engine.transaction.jta.
platform.internal.AtomikosJtaPlatform and  
   hibernate.transaction.coordinator_class to jta
I am using getCurrentSession for getting hibernate session.

I have to use Atomikos as JTA transaction manager as the development has to be happen in servlet container.

Thanks in advance for any help to find the gap in the configuration or any other issues..

Upvotes: 0

Views: 484

Answers (1)

Kuppusamy
Kuppusamy

Reputation: 153

The problem was with the maven Jetty plugin and the db connection created didn't persist the changes with hibernate 5 with maven jetty plugin 9.4.35.v20201120 though it was working with hibernate 3 and maven jetty plugin 7.0.1.v20091125. When I deployed the same war file with pre-configured data source in tomcat, able to persist the changes.

Upvotes: 1

Related Questions