我正在使用Spring Data JPA存储库和MySQL提供的流式结果集,以减少涉及扫描大型结果集的方法的内存消耗(这看起来越来越像是一种无望的徒劳尝试;理论上是为此使用流是很棒的;在实践中,约束非常难以使用)。
如果我试图在一个线程中开始使用第二个查询,而一个previos查询生成的流是未关闭的,我会得到一个这样的异常:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
...
Root cause: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
...
java.sql.SQLException: Streaming result set com.mysql.jdbc.RowDataDynamic@15f2d1f is still active. No statements may be issued when any streaming result sets are open and in use on a given connection. Ensure that you have called .close() on any active streaming result sets before attempting more queries.
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:868)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:864)
com.mysql.jdbc.MysqlIO.checkForOutstandingStreamingData(MysqlIO.java:3214)
...
不幸的是,当我在非常长的堆栈跟踪中找到我的代码时,当我看到它时,我看不到任何已分配但未处理的项目,所以我不确定发生了什么。如何查找未及时关闭的查询?