How to set fetchSize for iBatis select statement

后端 未结 2 2023
予麋鹿
予麋鹿 2021-01-02 10:22

I\'m using iBatis as ORM framework in Java. I have a select statement


                        
    
提交评论

  • 2021-01-02 10:47

    Yes you can set fetchSize at a higher level and need not worry about doing for every select.

    Step 1

    Create a file mybatis-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
        <settings>
            <setting name="lazyLoadingEnabled" value="false"/>
            <setting name="defaultFetchSize" value="5000"/>
        </settings>
    </configuration>
    

    You can add any value supported in mybatis http://www.mybatis.org/mybatis-3/configuration.html

    Step 2

    Load this as a resource in your Config file. This is Spring 4 example

    @Value("classpath:mybatis-config.xml")
    private Resource myBatisResource ;
    

    Step 3 : Pass to you SqlSessionFactoryBean

    sessionFactory.setConfigLocation(myBatisResource);
    

    Note: I did this with myBatis 3.3.0. It does not work with myBatis 3.4.4(there is open defect)

    This will ensure that all select statements have a fetchSize property assigned to them.

    0 讨论(0)
  • 提交回复
    热议问题