Error content
org.springframework.dao.TransientDataAccessResourceException: Cannot change the ExecutorType when there is an existing transaction
at org.mybatis.spring.SqlSessionUtils.sessionHolder(SqlSessionUtils.java:157)
at org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:91)
at com.baomidou.mybatisplus.core.toolkit.sql.SqlHelper.sqlSessionBatch(SqlHelper.java:55)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.sqlSessionBatch(ServiceImpl.java:75)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveOrUpdateBatch(ServiceImpl.java:172)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveOrUpdateBatch(ServiceImpl.java:163)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl$$FastClassBySpringCGLIB$$76535273.invoke(<generated>)
Actual use method (error example)
@Override
@Transactional(rollbackFor = Exception.class)
public BaseResp saveOrUpdate(TestPlanParam param) {
//add, update
============================================================
Omit the codes
============================================================
//1.New, updated firefighting plans (now with additional master tables)
this.saveOrUpdate(planEntity);
Integer testPlanId = planEntity.getId();
List<PlanTestTeamEntity> teamEntities=new ArrayList<>();
List<PlanTestResourceEntity> resourceEntities=new ArrayList<>();
//2.Add update firefighting team (bulk add schedule, need to hook up the id of the main table)
teams.forEach(team->{
PlanTestTeamEntity teamEntity=new PlanTestTeamEntity();
BeanUtil.copyProperties(team,teamEntity);
teamEntity.setFireFightTestPlanId(testPlanId);
//planTestTeamService.saveOrUpdate(teamEntity); Solution, using an article-by-article update
teamEntities.add(teamEntity);
});
//3.Add update of fire fighting supplies (bulk add schedule, need to hook up the id of the main table)
resources.forEach(res->{
PlanTestResourceEntity resourceEntity=new PlanTestResourceEntity();
BeanUtil.copyProperties(res,resourceEntity);
resourceEntity.setFireFightTestPlanId(testPlanId);
//planTestResourceService.saveOrUpdate(resourceEntity); Solution, using an article-by-article update
resourceEntities.add(resourceEntity);
});
planTestTeamService.saveOrUpdateBatch(teamEntities);
planTestResourceService.saveOrUpdateBatch(resourceEntities);
return BaseResp.success();
}
Error reporting reason
Executortype cannot be changed when a transaction exists
Solution:
When batch updating, first check out all the updated objects, and then update them circularly
Similar Posts:
- [Solved] return null from a method with a primitive return type (int).
- com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
- How to Solve MyBatisPlus Error: Failed to process, please exclude the tableName or statementId
- [Solved] mybatis-plus getById() Method Error: Expected one result (or null) to be returned by selectOne(), but found: 2
- Handler dispatch failed; nested exception is java.lang.StackOverflowError
- [Solved] The bean ‘sysDictService’ could not be injected because it is a JDK dynamic proxy
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.southwind.mmall002.service.Impl.ProductCategoryServiceImplTest’:
- [Solved] Caused by: java.lang.ClassNotFoundException: org.mybatis.logging.LoggerFactory
- curl curl_exec Problem with the SSL CA cert (path? access rights?)
- [Solved] com.hazelcast.spi.exception.RetryableHazelcastException:HazelcastInstance is not active!