gpt4 book ai didi

java - EJB 3 预加载

转载 作者:行者123 更新时间:2023-11-30 11:20:05 25 4
gpt4 key购买 nike

我使用 EJB 3。我有基类 A 和依赖类 B、C、D

@Entity
@Table(name = "A")
public class A implements Serializable {

@OneToMany(cascade = CascadeType.ALL)
private List<B> bs;

@OneToMany(cascade = CascadeType.ALL)
private List<C> cs;

@OneToMany(cascade = CascadeType.ALL)
private List<D> ds;

}

我有问题。我怎样才能急切地加载所有表格?我想使用 em.find(A.class, id);

最佳答案

您必须在 OneToMany 注释中使用 fetch 属性,以便:

@Entity
@Table(name = "A")
public class A implements Serializable {

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<B> bs;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<C> cs;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<D> ds;

}

关于java - EJB 3 预加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22919459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com