java - 带分页的QueryDsl
问题描述
我有 Spring jpa 的 QueryDsl 查询,如下所示:
JPAQuery<FooEntity> query = getQuerydsl()
.<FooEntity>createQuery()
.from(foo)
.leftJoin(foo.bar, bar).fetchJoin()
.leftJoin(...).fetchJoin()
.where(predicate)
.distinct();
return new PageImpl<>(getQuerydsl().applyPagination(pageable, query).fetch(), pageable,
query.fetchCount());
使用 FetchJoin 是因为需要来自连接表的数据。奇怪的是,其中一些查询具有正确的 SQL 结尾limit ?,?
。这意味着在数据库内部应用了分页。
但如果映射是通过@OneToMany(mappedBy = "...")
and not完成的@JoinColumn()
,那么所有数据都会加载到内存中,我会看到警告:
HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
在这种情况下如何避免将所有数据加载到内存中?
解决方案
推荐阅读
- java - 无法在 Android 10 中创建目录
- sql-server - 更改 SQL Server 默认系统日志的日志目录
- python - 重命名列后 Head() 不起作用
- android - 找不到参数的方法 implementation() [androidx.appcompat:appcompat:1.1.0-rc01]
- bash - Snort 2.9.15 快速安装脚本?
- python - 定位 dataframe-column-title 第一个字母发生变化的列
- c# - 如何找到知道孩子的父元素
- c# - 为日期格式配置 TextFormField
- angular - 使用标头身份验证在 Angular 中下载大文件
- json - 将 JSON Schema 中的数组映射到 OWL