FastResultSetHandler - not closing ResultSet?

67 views
Skip to first unread message

petr.27

unread,
Jan 7, 2011, 5:06:12 PM1/7/11
to mybatis-user
Hi,

we are using mybatis (3.0.4), mybatis-spring (1.0.1-SNAPSHOT :-),
spring 3.0.5) in our project. Database is Informix.

In one transaction we are in loop calling stored procedure
(complicated business, couldn't be changed), which at first drop temp
table "tmp1" if exists, than creates temp table "tmp1" and fill it.
Than we select row from this temp table and than call procedure again,
select again etc.

The problem is that FastResultSetHandler is not closing rs (in method
handleResultSets). So we run in problems in second (and all others)
call. Temp table couldn't be dropped because result set for select
from this table is not closed.

My question is, if there is some reason to do not close result set? Or
is it bug?

If container will not close result set automatically (in our case
JBoss is doing that, but it is complaining that we are not closing
result sets ourself :-)), than it could be serious problem.

Thank you very much for answer!

Petr Sigl

----------------------------

I fixed it for us and it is working now. But I am not sure if it is
right (maybe it could be helpful for you :-)).

FastResultSetHandler - starts at line 108:
--- fix ---
public List handleResultSets(Statement stmt) throws SQLException {
final List multipleResults = new ArrayList();
final List<ResultMap> resultMaps =
mappedStatement.getResultMaps();
int resultMapCount = resultMaps.size();
int resultSetCount = 0;
ResultSet rs = stmt.getResultSet();
validateResultMapsCount(rs,resultMapCount);
while (rs != null && resultMapCount > resultSetCount) {
final ResultMap resultMap = resultMaps.get(resultSetCount);
handleResultSet(rs, resultMap, multipleResults);
//close active result set, must be before getting next result
set
closeResultSet(rs);
rs = getNextResultSet(stmt);
cleanUpAfterHandlingResultSet();
resultSetCount++;
}
return collapseSingleResultList(multipleResults);
}

private void closeResultSet(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
//ignore
}
}
}
--- fix ---

petr.27

unread,
Jan 17, 2011, 8:41:07 AM1/17/11
to mybatis-user
Reply all
Reply to author
Forward
0 new messages