Transactions Springboot Mybatis事务回滚不';行不通
我正在使用Mybatis事务服务Transactions Springboot Mybatis事务回滚不';行不通,transactions,mybatis,rollback,Transactions,Mybatis,Rollback,我正在使用Mybatis事务服务 @Bean(name="sqlSession", destroyMethod="clearCache") public SqlSession sqlSession() throws Exception{ //SqlSessionTemplate sessionTemplate = new SqlSessionTemplate(SqlSessionFactory()); SqlSes
@Bean(name="sqlSession", destroyMethod="clearCache")
public SqlSession sqlSession() throws Exception{
//SqlSessionTemplate sessionTemplate = new SqlSessionTemplate(SqlSessionFactory());
SqlSessionTemplate sessionTemplate = new SqlSessionTemplate(SqlSessionFactory(),ExecutorType.BATCH);
return sessionTemplate;
}
这是我的事务设置
@Transactional
public void bulkInsert(int raffleNo, List<RaffleData> raffleDataList) throws DataAccessException {
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
long startTime = System.currentTimeMillis();
try{
//batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
batchSession.insert("raffle.insertBulkRaffleData", raffleDataList);
batchSession.commit();
}catch(Throwable throwable){
logger.error("Throwable ..... ");
batchSession.rollback();
throw new PersistenceException(throwable);
}
finally{
batchSession.flushStatements();
batchSession.close();
}
long endTime = System.currentTimeMillis();
logger.error("Bulk Insert Time : " + (endTime-startTime)/1000 + "(ms)");
}
@Transactional
public void bulkInsert(int-raffleNo,List-raffleDataList)抛出DataAccessException{
SqlSession batchSession=sqlSessionFactory.openSession(ExecutorType.BATCH,false);
long startTime=System.currentTimeMillis();
试一试{
//batchSession=sqlSessionFactory.openSession(ExecutorType.BATCH,false);
batchSession.insert(“raffle.insertBulkRaffleData”,raffleDataList);
batchSession.commit();
}捕捉(可抛可抛){
logger.error(“可丢弃…”);
batchSession.rollback();
抛出新的PersistenceException(可丢弃);
}
最后{
batchSession.flushStatements();
batchSession.close();
}
long-endTime=System.currentTimeMillis();
logger.error(“大容量插入时间:+(结束时间开始时间)/1000+”(毫秒)”;
}
但是回滚服务不起作用。。。我不知道原因
我使用的是mariadb和innodb引擎如果使用的是
@Transactional
,则不应在代码中调用commit()
或rollback()
(请参阅mybatis spring)。这显示了一个典型的服务实现。感谢您的帮助
@Transactional
public void bulkInsert(int raffleNo, List<RaffleData> raffleDataList) throws DataAccessException {
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
long startTime = System.currentTimeMillis();
try{
//batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
batchSession.insert("raffle.insertBulkRaffleData", raffleDataList);
batchSession.commit();
}catch(Throwable throwable){
logger.error("Throwable ..... ");
batchSession.rollback();
throw new PersistenceException(throwable);
}
finally{
batchSession.flushStatements();
batchSession.close();
}
long endTime = System.currentTimeMillis();
logger.error("Bulk Insert Time : " + (endTime-startTime)/1000 + "(ms)");
}