WARNING: firstResult/maxResults specified with collection fetch; applying in memory!
QueryTranslatorImpl
@Override
public List list(SessionImplementor session, QueryParameters queryParameters)
throws HibernateException {
// Delegate to the QueryLoader...
errorIfDML(); final QueryNode query = (QueryNode) sqlAst;
final boolean hasLimit = queryParameters.getRowSelection() != null && queryParameters.getRowSelection().definesLimits();
final boolean needsDistincting = ( query.getSelectClause().isDistinct() || hasLimit ) && containsCollectionFetches(); QueryParameters queryParametersToUse;
if ( hasLimit && containsCollectionFetches() ) {
LOG.firstOrMaxResultsSpecifiedWithCollectionFetch();
RowSelection selection = new RowSelection();
selection.setFetchSize( queryParameters.getRowSelection().getFetchSize() );
selection.setTimeout( queryParameters.getRowSelection().getTimeout() );
queryParametersToUse = queryParameters.createCopyUsing( selection );
}
else {
queryParametersToUse = queryParameters;
} List results = queryLoader.list( session, queryParametersToUse ); if ( needsDistincting ) {
int includedCount = -1;
// NOTE : firstRow is zero-based
int first = !hasLimit || queryParameters.getRowSelection().getFirstRow() == null
? 0
: queryParameters.getRowSelection().getFirstRow();
int max = !hasLimit || queryParameters.getRowSelection().getMaxRows() == null
? -1
: queryParameters.getRowSelection().getMaxRows();
List tmp = new ArrayList();
IdentitySet distinction = new IdentitySet();
for ( final Object result : results ) {
if ( !distinction.add( result ) ) {
continue;
}
includedCount++;
if ( includedCount < first ) {
continue;
}
tmp.add( result );
// NOTE : ( max - 1 ) because first is zero-based while max is not...
if ( max >= 0 && ( includedCount - first ) >= ( max - 1 ) ) {
break;
}
}
results = tmp;
} return results;
}
hasLimit && containsCollectionFetches()
这句判断,如果满足了这个条件,RowSelection将会被重新生成,原本分页需要的firstRow和maxRows属性将会丢失,后面的数据库分页自然也无法进行。
Hibernate这么做的原因从代码上也很容易理解,如果查询需要限制条数(limit/offset)并且需要fetch结合对 象,则重新生成RowSelection。 进一步解释,就是当一个实体(A)和另一个实体(B)是One-To-Many关系的时候,一个需要fetch 的典型查询语句是
“select distinct a from A a left join fetch a.b”
由于1个A可能对应多个B,这个时候数据库查询的结果条数和需要生成的A对象的条数可能不一致,
所以无法利用数据库层的分页来实现,因为你真正想分页的是A而不是A left join B。 出现这个警告就是提醒你这个查询实际上是查询了所有满足条件的数据,Hibernate是在内存中对其进行了假分页的处理。
WARNING: firstResult/maxResults specified with collection fetch; applying in memory!的更多相关文章
- 提高spring boot jpa性能(译)
Spring Data JPA为Spring应用程序提供了数据访问层的实现.这是一个非常方便的组件,因为它不会重新发明每个新应用程序的数据访问方式,因此您可以花更多时间来实现业务逻辑.使用Spring ...
- Tomcat7 JDK8 Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000540000000, 5368709120, 0) failed; error='Cannot allocate memory' (errno=12)
[root@crm-web- bin]# shutdown.sh bash: shutdown.sh: command not found [root@crm-web- bin]# sh shutdo ...
- 2.5 – Garbage Collection 自动垃圾回收 Stop-the-world vs. incremental vs. concurrent 垃圾回收策略
2.5 – Garbage Collection 自动垃圾回收 Lua 5.3 Reference Manual http://www.lua.org/manual/5.3/manual.html# ...
- POJ 1632 Vase collection【状态压缩+搜索】
题目传送门:http://poj.org/problem?id=1632 Vase collection Time Limit: 1000MS Memory Limit: 10000K Total ...
- [转载]Quartus ii 一些Warning/Eeror分析与解决
我会在此基础上继续添加 原文地址:ii 一些Warning/Eeror分析与解决">Quartus ii 一些Warning/Eeror分析与解决作者:yanppf 注:http:// ...
- SSH综合练习-仓库管理系统-第二天
SSH综合练习-仓库管理系统-第二天 今天的主要内容: 货物入库 页面信息自动补全回显功能:(学习目标:练习Ajax交互) 根据货物简记码来自动查询回显已有货物(Ajax回显) 根据货物名来自动查询补 ...
- Oracle12c版本中未归档隐藏参数
In this post, I will give a list of all undocumented parameters in Oracle 12.1.0.1c. Here is a query ...
- Oracle11g版本中未归档隐藏参数
In this post, I will give a list of all undocumented parameters in Oracle 11g. Here is a query to se ...
- Git for Windows v2.11.0 Release Notes
homepage faq contribute bugs questions Git for Windows v2.11.0 Release Notes Latest update: December ...
随机推荐
- greendao引起的NoClassDefFoundError异常解决
在使用Android studio导入eclipse工程师报错,因为原工程引用了greendao的第三方工程包 java.lang.NoClassDefFoundError: org.greenrob ...
- 概率霍夫变换(Progressive Probabilistic Hough Transform)原理详解
概率霍夫变换(Progressive Probabilistic Hough Transform)的原理很简单,如下所述: 1.随机获取边缘图像上的前景点,映射到极坐标系画曲线: 2.当极坐标系里面有 ...
- IOC容器特性注入第三篇:Attribute封装
Attribute(特性)=>就是对类,方法,字段的自定义属性的基类.可以利用Attribute对类,方法等进行自定义描述,方便区分. 既然如此,那我们就可以那些需要注入IOC容器和不需要注入I ...
- ef 某些字段更新 某些字段不更新
不更新 _pocDbContext.Entry<UploadFileActiveTask>(activeTask).Property("id").IsModified ...
- [Android] 基于 Linux 命令行构建 Android 应用(七):自动化构建
本章将演示如何基于 Linux 命令行构建 Android 应用,在开始本章之前,希望你已经阅读之前几章内容. 本文环境为 RHEL Sandiego 32-bits,要基于 Linux CLI 构建 ...
- [Android] 基于 Linux 命令行构建 Android 应用(一):关于 Android 项目
关于 Android 项目 项目是保存源代码和资源文件的容器. 谷歌提供的 Android SDK 工具只能对具有固定目录结构的项目进行编译和打包.因此强烈建议使用 Eclipse + ADT 或者 ...
- 【laravel5.6】The Process class relies on proc_open, which is not available on your PHP installation.
部署服务器的时候,使用composer来安装依赖.遇到了 解决办法: 在php.ini中,找到disable_functions选项,看看后面是否有proc_open函数被禁用了,如果有的话,去掉即可
- rar压缩find查找到的文件
find . -name 'CMakeLists.txt' | xargs /d/Program\ Files/WinRAR/rar.exe a -r ./out.rar $ ------------ ...
- ElasticSearch5.X的冷热数据架构
转载:https://my.oschina.net/xiaomaijiang/blog/826701 当使用ElasticSearch做大规模的时序数据分析的时候,我们建议使用基于时序的索引并且采用3 ...
- for循环将字典添加到列表中出现覆盖前面数据的问题
出现问题: rets = [{'id':1},{"id":2},{"id":3}] context = {} context['count'] = len(re ...