java - 限制在 JPA Eclipse 中获取的子记录link
问题描述
我有一个包含子实体列表的父实体。有一些新的子实体被创建并设置为父实体。代码片段如下所示。
public class ParentEntity {
@OneToMany(fetch=FetchType.LAZY, mappedBy="parentField", cascade=CascadeType.ALL)
private List<ChildEntityA> childAList = new ArrayList<>();
}
public class BusinessLogic {
public void methodA() {
ParentEntity parent = parentRepository.getById();
parent.setFieldA("fieldA");
ChildEntityA child1 = new ChildEntityA();
child1.setField1("field1");
ChildEntityA child2 = new ChildEntityA();
child2.setField1("field1");
List<ChildEntityA> childAList = new ArrayList<>();
childAList.add(child1);
childAList.add(child2);
parent.setChildAList(childAList);//This triggers a select call on DB table associated with Child A and fetches all the records
entityManager.merge(parent);
}
}
我的问题是 parent.setChildAList(childAList); 触发对子数据库表的 SELECT 查询,并获取数百万条不需要的记录。有没有办法限制被检索的子记录的数量或一起阻止?全选导致 GC 抖动并影响性能。
JPA 是规范,Eclipselink 是我的提供者。对此的任何帮助将不胜感激。提前致谢。
解决方案
推荐阅读
- c++ - 设置者不更改类中向量的数据
- html - CSS3 链接样式没有被一致地采用
- python - 从具有多个登录名的文本文件创建登录系统
- dart - 使用 path_provider 到 video_player 获取下载的文件路径时出错
- maven - mvn 依赖:树、多模块和 ${revision}
- python - 使用 django 2.2 不断收到 404 错误
- sql - 使用SQL的多表组合PIVOT表
- python - Choropleth 地图未在输出中显示颜色变化
- bash - 无法使用 printf 输出负数,但 echo 有效
- laravel - SQLSTATE [42S02]:未找到基表或视图:1146 错误 laravel