Mybatis always loads entire result set into memory?

539 views
Skip to first unread message

Bryan

unread,
Feb 13, 2011, 6:07:00 PM2/13/11
to mybatis-user
I have a query that returns a huge result set. I'm using a server-side
cursor on Postgres by setting the "fetchSize" attribute on my query. I
would like to "stream" through millions of rows and do some
processing. I thought I would be able to do this by specifying my own
ResultHandler, e.g.

sqlSession.select("processData", params, new ResultHandler() {
...
});

This would bypass the DefaultResultHandler which loads everything into
a list. Just to note, my mapping has a join mapping so internally
MyBatis uses the NestedResultSetHandler.

The NestedResultSetHandler always loads the entire result set into a
map, and it does the join in memory. I obviously don't want this
behavior.

What I would like to do is do the join mapping based on the order of
the result set, i.e. keep joining until the ID changes. Then the
entire result set would not need to be loaded into memory.

Is there a way to override the NestedResultSetHandler? I saw the
Configuration.newResultSetHandler() method, and thought this might be
a way. I definitely do NOT want the entire result set in memory.

Larry Meadors

unread,
Feb 13, 2011, 7:57:52 PM2/13/11
to mybati...@googlegroups.com
Do the join in sql instead of with mybatis and use a custom row handler.

Larry

Bryan

unread,
Feb 14, 2011, 1:02:23 PM2/14/11
to mybatis-user
Not sure what you understood what I was saying. I AM doing the join in
SQL, and I AM using a custom result handler. The problem is MyBatis
still loads the entire result set into a map, even when using a custom
result handler, so it can do the collection mapping.

Larry Meadors

unread,
Feb 14, 2011, 1:06:29 PM2/14/11
to mybati...@googlegroups.com
I'm saying ditch the collection mapping and do it in the result handler.

Larry

Bryan

unread,
Feb 14, 2011, 3:44:50 PM2/14/11
to mybatis-user
Then I will need two data structures, one to hold the result of the
query, and used by Mybatis for mapping, and one to hold the result
object with the collection. Not exactly what I was looking for.

Larry Meadors

unread,
Feb 14, 2011, 4:01:32 PM2/14/11
to mybati...@googlegroups.com
Heh, neither was loading the entire data set. What's the lesser evil? :)
Reply all
Reply to author
Forward
0 new messages