當我將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>
編輯: 我嘗試手動犯在我的方法結束但是數據依然沒有被保存
@Autowired應該在事務結束時提交。我在我的方法結束時嘗試手動提交,但數據仍未保存,並且出現錯誤,說明事務已完成,可能已回滾。 'org.springframework.transaction.UnexpectedRollbackException:JTA事務已經完成 - 可能回滾了' – darthNater 2014-12-10 21:59:39
@ user2631291不是它不是 – darrengorman 2014-12-10 21:59:57
有沒有辦法查看事務是否回滾? – darthNater 2014-12-10 22:10:05