事务未提交

inkz8wg9  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(403)

从事spring5和hibernate项目。使用spring进行bean管理、事务和mvc。虽然我可以在日志中看到insert语句,但更改没有提交到数据库。没有错误。select语句没有问题。我可以登录到应用程序。以下是我的配置:
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.

提前感谢您的帮助,以找出配置中的差距或任何其他问题。。

zhte4eai

zhte4eai1#

问题出在maven jetty插件上,创建的db连接没有保留hibernate 5和maven jetty插件9.4.35.v20201120的更改,尽管它使用的是hibernate 3和maven jetty插件7.0.1.v20091125。当我在tomcat中使用预配置的数据源部署同一个war文件时,能够持久化更改。

相关问题