我会尽量在这里尽可能简洁。我已经经历了网上报道的众多类似问题,并评估了我的问题。但是,它没有解决我的问题。所以最后我把它放了。
我有一个带有默认值的spring注释事务服务(在已实现的类方法上注释)。该服务通过直接调用mybatis映射器方法(在服务中自动装配)进行一些插入(在循环内)和无参数存储过程调用。
我发现事务没有回滚异常(运行时异常,就像Spring所期望的那样)。我通过评论存储的proc调用进行测试,插入时不使用循环,但这没有帮助。
查看日志,我发现虽然事务同步按预期进行了回滚,Spring正在切换到手动提交。我不确定这是否会导致问题?
我在Tomcat和驱动程序管理器连接单元测试上使用JNDI连接进行了测试,两者的行为相同。以下是日志的摘录:
====================================== Using DriverManagerDataSource testing ====================================== 2014-10-17 12:34:17 [main] DEBUG DataSourceTransactionManager - Creating new transaction with name [com.ericsson.prf.web.service.impl.ReportingService.saveHeadcountCorrectionsJSON]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' 2014-10-17 12:34:17 [main] DEBUG DriverManagerDataSource - Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/PRFDB] 2014-10-17 12:34:17 [main] DEBUG DataSourceTransactionManager - Acquired Connection [com.mysql.jdbc.JDBC4Connection@728cacdc] for JDBC transaction 2014-10-17 12:34:17 [main] DEBUG DataSourceTransactionManager - Switching JDBC Connection [com.mysql.jdbc.JDBC4Connection@728cacdc] to manual commit 2014-10-17 12:34:17 [main] DEBUG SqlSessionUtils - Creating a new SqlSession 2014-10-17 12:34:17 [main] DEBUG SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@114d4c11] 2014-10-17 12:34:17 [main] DEBUG SpringManagedTransaction - JDBC Connection [com.mysql.jdbc.JDBC4Connection@728cacdc] will be managed by Spring 2014-10-17 12:34:17 [main] DEBUG updateHeadcountPlanned - ooo Using Connection [com.mysql.jdbc.JDBC4Connection@728cacdc] 2014-10-17 12:34:17 [main] DEBUG updateHeadcountPlanned - ==> Preparing: UPDATE PRF_HEADCOUNT_PLANNED SET COUNT=? WHERE ID=? 2014-10-17 12:34:17 [main] DEBUG updateHeadcountPlanned - ==> Parameters: 43(Integer), 1629(Long) 2014-10-17 12:34:17 [main] DEBUG SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@114d4c11] 2014-10-17 12:34:17 [main] DEBUG SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@114d4c11] from current transaction 2014-10-17 12:34:17 [main] DEBUG callLoadHCCostPlanned - ooo Using Connection [com.mysql.jdbc.JDBC4Connection@728cacdc] 2014-10-17 12:34:17 [main] DEBUG callLoadHCCostPlanned - ==> Preparing: {call load_sap_hc_cost_planned()} 2014-10-17 12:34:17 [main] DEBUG SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@114d4c11] 2014-10-17 12:34:18 [main] DEBUG SqlSessionUtils - Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@114d4c11] 2014-10-17 12:34:18 [main] DEBUG SqlSessionUtils - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@114d4c11] 2014-10-17 12:34:18 [main] DEBUG DataSourceTransactionManager - Initiating transaction rollback 2014-10-17 12:34:18 [main] DEBUG DataSourceTransactionManager - Rolling back JDBC transaction on Connection [com.mysql.jdbc.JDBC4Connection@728cacdc] 2014-10-17 12:34:18 [main] DEBUG DataSourceTransactionManager - Releasing JDBC Connection [com.mysql.jdbc.JDBC4Connection@728cacdc] after transaction 2014-10-17 12:34:18 [main] DEBUG DataSourceUtils - Returning JDBC Connection to DataSource ====================================== Using JndiObjectFactoryBean on Tomcat ====================================== 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG AnnotationTransactionAttributeSource - Adding transactional method 'saveHeadcountCorrectionsJSON' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'transactionManager' 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DataSourceTransactionManager - Creating new transaction with name [com.ericsson.prf.web.service.impl.ReportingService.saveHeadcountCorrectionsJSON]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DataSourceTransactionManager - Acquired Connection [jdbc:mysql://localhost:3306/PRFDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF8, UserName=prf@localhost, MySQL Connector Java] for JDBC transaction 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DataSourceTransactionManager - Switching JDBC Connection [jdbc:mysql://localhost:3306/PRFDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF8, UserName=prf@localhost, MySQL Connector Java] to manual commit 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SqlSessionUtils - Creating a new SqlSession 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46ee04fb] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SpringManagedTransaction - JDBC Connection [jdbc:mysql://localhost:3306/PRFDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF8, UserName=prf@localhost, MySQL Connector Java] will be managed by Spring 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG updateHeadcountPlanned - ooo Using Connection [jdbc:mysql://localhost:3306/PRFDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF8, UserName=prf@localhost, MySQL Connector Java] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG updateHeadcountPlanned - ==> Preparing: UPDATE PRF_HEADCOUNT_PLANNED SET COUNT=? WHERE ID=? 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG updateHeadcountPlanned - ==> Parameters: 43(Integer), 1629(Long) 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46ee04fb] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46ee04fb] from current transaction 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG callLoadHCCostPlanned - ooo Using Connection [jdbc:mysql://localhost:3306/PRFDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF8, UserName=prf@localhost, MySQL Connector Java] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG callLoadHCCostPlanned - ==> Preparing: {call load_sap_hc_cost_planned()} 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46ee04fb] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SqlSessionUtils - Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46ee04fb] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG SqlSessionUtils - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46ee04fb] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DataSourceTransactionManager - Initiating transaction rollback 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DataSourceTransactionManager - Rolling back JDBC transaction on Connection [jdbc:mysql://localhost:3306/PRFDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF8, UserName=prf@localhost, MySQL Connector Java] 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DataSourceTransactionManager - Releasing JDBC Connection [jdbc:mysql://localhost:3306/PRFDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF8, UserName=prf@localhost, MySQL Connector Java] after transaction 2014-10-17 12:53:51 [http-bio-8080-exec-3] DEBUG DataSourceUtils - Returning JDBC Connection to DataSource
答案 0 :(得分:0)
因为我以为我错过了一些愚蠢的东西!数据库引擎是MyISAM,需要更改为InnoDB。这已经解决了。