@Transactional transaction does not work to solve

problem

        Use spring configuration annotations things @Transactional, found no effect at the time of testing.

surroundings

       

         Profiles

[html]  view plain copy See the code CODE on the sheet I derived the piece of code
  1. <bean id="studentMGDataSource" class="org.apache.commons.dbcp.BasicDataSource"  
  2.     destroy-method="close">  
  3.     <property name="driverClassName" value="${student_MG_jdbc.driver}" />  
  4.     <property name="url" value="${student_MG_jdbc.url}" />  
  5.     <property name="username" value="${student_MG_jdbc.username}" />  
  6.     <property name="password" value="${student_MG_jdbc.password}" />  
  7.     <property name="initialSize" value="${student_MG_jdbc.initialSize}" />  
  8.     <property name="maxActive" value="${student_MG_jdbc.maxActive}" />  
  9.     <property name="maxIdle" value="${student_MG_jdbc.maxIdle}" />  
  10.     <property name="maxWait" value="${student_MG_jdbc.maxWait}" />  
  11.     <property name="defaultAutoCommit" value="${student_MG_jdbc.defaultAutoCommit}" />  
  12. </bean>  
  13.   
  14. <bean id="studentMGSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  15.     <property name="configLocation" value="classpath:mybatis/mybatis-studentMG-config.xml" />  
  16.     <property name="dataSource" ref="studentMGDataSource" />  
  17. </bean>  
  18.   
  19. <bean id="studentMGSqlSession" class="org.mybatis.spring.SqlSessionTemplate">  
  20.     <constructor-arg index="0" ref="studentMGSqlSessionFactory" />  
  21. </bean>  
  22.   
  23. <bean id="studentMGTxManager"  
  24.     class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  25.     <property name="dataSource" ref="studentMGDataSource" />  
  26. </bean>  
  27.   
  28. <tx:annotation-driven proxy-target-class="true" transaction-manager="studentMGTxManager" />  

        Java code

[java]  view plain copy See the code CODE on the sheet I derived the piece of code
  1. @Transactional(value="studentMGTxManager",rollbackFor=java.lang.Exception.class)  
  2. public void saveStudentDto(List<StudentDto> dtoList, String classId) {  
  3.       
  4. }  

the reason

        Database storage engine used is MyISam, MyISam does not support something, you should use the InnoDB engine

TIPS

        @Transactional annotation transaction does not work to solve the
         possible reasons:
        1. To support transactional database engine
        if it is mysql, pay attention to the table to be used to support the transaction engine, such as innodb, if it is myisam, the transaction does not work

        2. whether to open analytical notes on the
        configuration file must be added to <tx: annotation-driven /> , or do not resolve @Transactional

Published 90 original articles · won praise 21 · views 470 000 +

Guess you like

Origin blog.csdn.net/yx13649017813/article/details/47661257