Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同类中调用saveBatch批处理失效 #4364

Closed
shin8085 opened this issue Mar 11, 2022 · 1 comment
Closed

同类中调用saveBatch批处理失效 #4364

shin8085 opened this issue Mar 11, 2022 · 1 comment

Comments

@shin8085
Copy link

当前使用版本(必填,否则不予处理)

Mybatis-plus:3.5.1
SQL Server 2019:15.0.4198.2

该问题是如何引起的?(确定最新版也有问题再提!!!)

我在一个A类中继承了ServiceImpl类,然后在A类中直接调用saveBatch发现效率非常低并且事务并没有生效,但是但我在B类中继承ServiceImpl后,在A类中调用b.saveBatch发现效率快了近十倍!
应该是同类中调用aop失效导致的,如果是这样的话岂不是只能在Controller层调用?或者单独再写一个service?

重现步骤(如果有就写完整)

class DataSyncApplicationTests extends ServiceImpl<DataMapper,Data> {
    @Test
    void contextLoads() throws Exception {
        MybatisPlusConfig.setTableIndex("001");
        StopWatch stopWatch=new StopWatch();
        List<Data> list=new ArrayList<>();
        for(int i=0;i<50000;i++){
            Data data=new Data();
            data.setId("test:"+i);
            data.setRemark("new");
            data.setResult("new");
            data.setClueId("nddd");
            data.setOwnerName("ffff");
            data.setAudioUrl("fffff");
            list.add(data);
        }
        stopWatch.start();
        saveBatch(list);
        stopWatch.stop();
        System.out.println(stopWatch.getLastTaskTimeMillis());
    }
}
2022-03-11 09:26:46.940  WARN 2208 --- [           main] b.xxx.xxxxxxx.DataSyncApplicationTests  : SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@60b5e80d] Transaction not enabled
42091
class DataSyncApplicationTests extends ServiceImpl<DataMapper,Data> {
    @Resource
    Bclass bclass;

    @Test
    void contextLoads() throws Exception {
        MybatisPlusConfig.setTableIndex("001");
        StopWatch stopWatch=new StopWatch();
        List<Data> list=new ArrayList<>();
        for(int i=0;i<50000;i++){
            Data date=new Data();
            date.setId("test:"+i);
            date.setRemark("new");
            date.setResult("new");
            date.setClueId("nddd");
            date.setOwnerName("ffff");
            date.setAudioUrl("fffff");
            list.add(date);
        }
        stopWatch.start();
        bclass.saveBatch(list);
        stopWatch.stop();
        System.out.println(stopWatch.getLastTaskTimeMillis());
    }
}
4930

报错信息

@lukelongcn
Copy link

我在一个A类中继承了ServiceImpl类,然后在A类中直接调用saveBatch发现效率非常低并且事务并没有生效

我猜测是因为在 A 类中直接调用 saveBatch 方法,没有经过 AOP ,所以 saveBatch 的 @transaction 注解没有生效,可以在 contextLoads() 方法上加上 @transaction 注解试试看。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants