有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在JPA Eclipselink中获取的java限制子记录

我有一个具有子实体列表的父实体。创建了一些新的子实体并将其设置为父实体。代码片段如下所示

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);
}
}

我的问题是父母。儿童主义者;触发对子DB表的SELECT查询,并获取数百万条不需要的记录。有没有办法限制检索到的子记录的数量,或者防止这些子记录一起被检索到?全选导致GC抖动并影响性能

JPA是规范,Eclipselink是我的提供商。 在此方面的任何帮助都将不胜感激。提前谢谢


共 (0) 个答案