problem
Use spring configuration annotations things @Transactional, found no effect at the time of testing.
surroundings
Profiles
- <bean id="studentMGDataSource" class="org.apache.commons.dbcp.BasicDataSource"
- destroy-method="close">
- <property name="driverClassName" value="${student_MG_jdbc.driver}" />
- <property name="url" value="${student_MG_jdbc.url}" />
- <property name="username" value="${student_MG_jdbc.username}" />
- <property name="password" value="${student_MG_jdbc.password}" />
- <property name="initialSize" value="${student_MG_jdbc.initialSize}" />
- <property name="maxActive" value="${student_MG_jdbc.maxActive}" />
- <property name="maxIdle" value="${student_MG_jdbc.maxIdle}" />
- <property name="maxWait" value="${student_MG_jdbc.maxWait}" />
- <property name="defaultAutoCommit" value="${student_MG_jdbc.defaultAutoCommit}" />
- </bean>
- <bean id="studentMGSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="configLocation" value="classpath:mybatis/mybatis-studentMG-config.xml" />
- <property name="dataSource" ref="studentMGDataSource" />
- </bean>
- <bean id="studentMGSqlSession" class="org.mybatis.spring.SqlSessionTemplate">
- <constructor-arg index="0" ref="studentMGSqlSessionFactory" />
- </bean>
- <bean id="studentMGTxManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="studentMGDataSource" />
- </bean>
- <tx:annotation-driven proxy-target-class="true" transaction-manager="studentMGTxManager" />
Java code
- @Transactional(value="studentMGTxManager",rollbackFor=java.lang.Exception.class)
- public void saveStudentDto(List<StudentDto> dtoList, String classId) {
- }
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