当我将defaultAutoCommit设置为false时,我的事务不会保存到数据库中。 有人知道为什么我的数据没有保存到数据库中吗?
我在我的方法上使用@transactional似乎提交了事务,因为状态为3
交易状态 https://docs.jboss.org/jbossas/javadoc/4.0.2/javax/transaction/Status.java.html
这是交易日志
2014-12-10 14:39:07,132 TRACE [http-apr-8080-exec-2] CacheSynchronization - 完成回调前的事务
2014-12-10 14:39:07,132 TRACE [http-apr-8080-exec-2] CacheSynchronization - 完成回调后的事务,状态:3
<aop:aspectj-autoproxy/>
<context:annotation-config/>
<!-- ******************************************************************** -->
<!-- Scan for dao layer annotated beans -->
<!-- ******************************************************************** -->
<context:component-scan base-package="package.dao" scoped-proxy="interfaces"/>
<!-- ******************************************************************** -->
<!-- Mark bean transactions as annotation driven -->
<!-- ******************************************************************** -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- ******************************************************************** -->
<!-- PropertyConfigurer for the DAO -->
<!-- ******************************************************************** -->
<context:property-placeholder location="classpath:prop-dao.properties"/>
<!-- ******************************************************************** -->
<!-- Setup the transaction manager -->
<!-- ******************************************************************** -->
<!-- Using Atomikos Transaction Manager -->
<bean class="com.atomikos.icatch.jta.UserTransactionManager" destroy-method="close" id="atomikosTransactionManager" init-method="init">
<property name="forceShutdown" value="true"/>
<property name="startupTransactionService" value="true"/>
<property name="transactionTimeout" value="600000"/>
</bean>
<bean class="com.atomikos.icatch.jta.UserTransactionImp" id="atomikosUserTransaction"/>
<!-- Configure the Spring framework to use JTA transactions from Atomikos -->
<bean class="org.springframework.transaction.jta.JtaTransactionManager" id="transactionManager">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
<property name="transactionSynchronizationName" value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION"/>
</bean>
<!-- ******************************************************************** -->
<!-- Setup a data source -->
<!-- ******************************************************************** -->
<!-- Using Apache DBCP Data Sources -->
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" name="propDS">
<property name="driverClassName" value="${prop.connection.driver_class}"/>
<property name="username" value="${prop.connection.username}"/>
<property name="password" value="${prop.connection.password}"/>
<property name="url" value="${prop.connection.url}"/>
<property name="maxIdle" value="${prop.minPoolSize}"/>
<property name="maxActive" value="${prop.maxPoolSize}"/>
<property name="defaultAutoCommit" value="false"/>
</bean>
<!-- ******************************************************************** -->
<!-- Setup each persistence unit -->
<!-- ******************************************************************** -->
<!-- Configure a JPA vendor adapter -->
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" id="propJPAVendorAdapter">
<property name="showSql" value="${prop.show_sql}"/>
<property name="generateDdl" value="${prop.generateDdl}"/>
<property name="databasePlatform" value="${prop.dialect}"/>
</bean>
<!-- EntityManager Factory that brings together the persistence unit, datasource, and JPA Vendor -->
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="prop">
<property name="dataSource" ref="propDS"/>
<property name="persistenceUnitName" value="prop"/>
<property name="jpaVendorAdapter" ref="propJPAVendorAdapter"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
<entry key="hibernate.connection.release_mode" value="on_close"/>
</map>
</property>
</bean>
编辑: 我尝试在方法结束时手动提交,但数据仍未保存
答案 0 :(得分:1)
当我将defaultAutoCommit设置为false时,我的交易不会被保存 到数据库
这是将defaultAutoCommit设置为false的目的。 将其设置为true,它将自动提交。 将其设置为false,您需要手动提交它,否则它将被回滚。