我正在使用 org. 休眠。流模式下的 ScrollableResults。
我确保我不会遇到 n+1 问题。并将所有连接放在同一个 SQL 语句中。
由于某种原因,在while循环中我遇到了一个异常,在此之前我可以看到一个额外的选择(在我们在流模式下工作时我们期望的第一个选择旁边)
知道我错过了什么吗?
我的滚动条:
protected void scroll(ScrollableHandler<T> handler,String namedQuery, Object... values){
T previousEntity=null;
Session s = null;
ScrollableResults results = null;
try {
s = (Session) em.getDelegate();
org.hibernate.Query query = s.getNamedQuery(namedQuery);
for (int i = 0; i < values.length; i++)
query.setParameter(i, values[i]);
results = query.setFetchSize(fetchSize).scroll(ScrollMode.FORWARD_ONLY);
while(results.next()) -> here I get the exception
{
T entity = (T) results.get(0);
if (null != entity &&
(! entity.equals(previousEntity))) {
handler.handle(entity);
previousEntity = entity;
}
s.clear();
}
} finally {
if (results != null)
results.close();
}
}
日志:
11:54:24,182 WARN SqlExceptionHelper:143 - SQL Error: 0, SQLState: null
11:54:24,182 ERROR SqlExceptionHelper:144 - Streaming result set com.mysql.jdbc.RowDataDynamic@729d8721 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.
11:54:24,183 WARN CollectionLoadContext:347 - HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [3] entries
Exception in thread "Thread-11" java.lang.RuntimeException: Could not export
谢谢,雷。