Ibatis queryWithRowHandler() still seems to fetch all rows

寵の児 提交于 2019-12-13 03:30:46

问题


I'm using Ibatis 2.3.4 and Mysql 5.1.37, with mysql-java-connector 5.1.6 with java 1.6

I have query that returns very many rows from a single table. In order to do this the manual suggests to use queryWithRowHandler(). However when I call this query it internally still seems to fetch all rows (memory goes up very fast before the first handleRow() call is done.

How can I tell Ibatis to fetch small at the time portions (I can of course use several queries returning lists of smaller results, but in my opinion this is precisely what ibatis should do for me)?

EDIT: I've tried setting a fetchSize of 100 for the statement, this doesn't seem to do anything, same for resultSetType="FORWARD_ONLY". lazyLoadingEnabled isn't set anywhere, so should be enable.


回答1:


After doing more thorough search, I found that the mysql manual on the jbdc implementation and the mysql issue database had some useful information. This boils down to needing the following:

The JDBC driver needs a setting to use cursor (this might have some downsides too)

  <transactionManager type="JDBC" commitRequired="false">
    <dataSource type="SIMPLE">
       ...
      <property name="Driver.useCursorFetch" value="true"/>
    </dataSource>
  </transactionManager>

The statement needs the following properties (with any useful value fetchSize).

fetchSize="1000" resultSetType="FORWARD_ONLY"


来源:https://stackoverflow.com/questions/3870500/ibatis-querywithrowhandler-still-seems-to-fetch-all-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!