spring-boot MyBatisBatchItemWriter Cannot change the ExecutorType when there is an existing transaction -
i'm use spring boot , mybatis mybatisbatchitemwriter. using demo write data(mysql) database when no problem. used in project org.springframework.dao.transientdataaccessresourceexception: cannot change executortype when there existing transaction @ 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(unknown source) ~[na:na]
this demo:
@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; }
this 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; }
why demo ok project has error?
because sais it: can't change executor type inside transaction.
it looks you've tried batch-write part of more broad transaction includes other sql operations, transaction started simple (default) or reuse executor type.
it's obvious, batch-write requires batch executor type, though once transaction started, it's executor type can not changed. so, perform batch operations in separate transaction, or run nested transaction, if rdbms allows it.
Comments
Post a Comment