Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 存在现有事务时,spring boot MyBatisBatchItemWriter无法更改ExecutorType_Spring Boot - Fatal编程技术网

Spring boot 存在现有事务时,spring boot MyBatisBatchItemWriter无法更改ExecutorType

Spring boot 存在现有事务时,spring boot MyBatisBatchItemWriter无法更改ExecutorType,spring-boot,Spring Boot,我正在使用spring boot和mybatis MyBatisBatchItemWriter。 在没有问题时使用demo将数据(mysql)写入数据库。 但在我的项目中使用 org.springframework.dao.TransientDataAccessResourceException:存在现有事务时无法更改ExecutorType 在org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:91)~[m

我正在使用spring boot和mybatis MyBatisBatchItemWriter。 在没有问题时使用demo将数据(mysql)写入数据库。 但在我的项目中使用
org.springframework.dao.TransientDataAccessResourceException:存在现有事务时无法更改ExecutorType
在org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:91)~[mybatis-spring-1.2.2.jar:1.2.2]
在org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:353)~[mybatis-spring-1.2.2.jar:1.2.2]
在com.sun.proxy.$Proxy45.update(未知源)~[na:na]

这是我的演示:

 @Bean
public MyBatisBatchItemWriter<Hfbank> writer() {
    MyBatisBatchItemWriter<Hfbank> writer = new MyBatisBatchItemWriter<Hfbank>();
    writer.setSqlSessionFactory(sqlSessionFactory);
    String statementId = "com.springboot.dao.HfbankDao.insertSelective";
    writer.setStatementId(statementId);
    CompositeItemWriter compositeItemWriter  = new CompositeItemWriter();
     List delegates = new ArrayList();
     delegates.add(writer);
     compositeItemWriter.setDelegates(delegates);
     writer.setAssertUpdates(false);
    return writer;
}
@Bean
公共MyBatisBatchItemWriter编写器(){
MyBatisBatchItemWriter=新的MyBatisBatchItemWriter();
writer.setSqlSessionFactory(sqlSessionFactory);
String语句ID=“com.springboot.dao.HfbankDao.insertSelective”;
writer.setStatementId(statementId);
CompositeItemWriter CompositeItemWriter=新的CompositeItemWriter();
列表委托=新建ArrayList();
添加(作者);
compositeItemWriter.SetDelegories(委托);
writer.setAssertUpdate(false);
返回作者;
}
这是我的MyBatisBatchItemWriter:

@Bean
 @StepScope
public MyBatisBatchItemWriter<ChannelDataInfo> writer(@Value("#{jobParameters[channelid]}")  Long channelid) {
    MyBatisBatchItemWriter<ChannelDataInfo> writer = new MyBatisBatchItemWriter<ChannelDataInfo>();
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);

    writer.setSqlSessionFactory(sqlSessionFactory);
    String statementId = "com.kaigejava.fundcheck.repository.ChannelDataInfoRepository.insertSelective";

    writer.setStatementId(statementId);
    CompositeItemWriter compositeItemWriter  = new CompositeItemWriter();
     List delegates = new ArrayList();
     delegates.add(writer);
     compositeItemWriter.setDelegates(delegates);
     writer.setAssertUpdates(false);
    return writer;
}
@Bean
@步进镜
公共MyBatisBatchItemWriter编写器(@Value(“#{jobParameters[channelid]}”)长channelid){
MyBatisBatchItemWriter=新的MyBatisBatchItemWriter();
SqlSession SqlSession=sqlSessionFactory.openSession(ExecutorType.BATCH);
writer.setSqlSessionFactory(sqlSessionFactory);
String statementId=“com.kaigejava.fundcheck.repository.ChannelDataInfoRepository.insertSelective”;
writer.setStatementId(statementId);
CompositeItemWriter CompositeItemWriter=新的CompositeItemWriter();
列表委托=新建ArrayList();
添加(作者);
compositeItemWriter.SetDelegories(委托);
writer.setAssertUpdate(false);
返回作者;
}

为什么演示可以,但我的项目有错误?

因为它说:您不能更改事务中的执行器类型

看起来您试图批量编写一些东西,作为包含其他SQL操作的更广泛事务的一部分,但该事务是以简单(默认)或重用执行器类型启动的


很明显,批写入需要批执行器类型,尽管一旦事务启动,它的执行器类型就不能更改。因此,如果RDBMS允许,可以在单独的事务中执行批处理操作,或者运行嵌套事务。

因为它是这样的:您不能更改事务中的执行器类型

看起来您试图批量编写一些东西,作为包含其他SQL操作的更广泛事务的一部分,但该事务是以简单(默认)或重用执行器类型启动的

很明显,批写入需要批执行器类型,尽管一旦事务启动,它的执行器类型就不能更改。所以,如果RDBMS允许,可以在单独的事务中执行批处理操作,或者运行嵌套事务