How to set fetchSize for iBatis select statement

I am using iBatis as an ORM framework in Java. I have a select statement

<select id="getList" resultMap="correctMap"> SELECT * FROM SOME_TABLE </select> 

And I use the queryForList method:

 List<MappedObject> list = getSqlMapClientTemplate().queryForList("getList"); 

But it retrieves a large amount of data, and the performance of this query is rather slow.

My guess is that iBatis has a default sample size (for example, in JDBS - 10), so it is so slow. So I want to set a larger sample size (e.g. 1000). How can i do this?

Or was I looking for the wrong way?

NOTE. I need all the data, so the maximum results in the queryForList method queryForList not suitable for me.

 List queryForList(String id, Object parameterObject, int skip, int max) 
+7
source share
2 answers
 <select id="SELECT_TABLE" parameterType="String" fetchSize="500" resultType="hashmap"> SELECT * FROM TABLE WHERE NAME = #{value} </select> 
+10
source

Yes, you can set fetchSize to a higher level and you don’t have to worry about what to do for each choice.

Step 1

Create mybatis-config.xml file

 <?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

Download this as a resource to the configuration file. This is a Spring 4 example

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

Step 3: Pass SqlSessionFactoryBean to You

 sessionFactory.setConfigLocation(myBatisResource); 

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

This ensures that all select statements have the fetchSize property assigned to them.

0
source

All Articles