我有 2 个实体作为父实体和子实体作为 OneToMany 关系
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
@IndexColumn(name = "index", base = 1)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@LazyCollection(LazyCollectionOption.EXTRA)
private List<Child> childs = new ArrayList<Child>();
// getter and setter
}
那么这里有什么用@LazyCollection(LazyCollectionOption.EXTRA)它什么时候会出现在图片中,比如对于子列表的哪些操作,它将是有益的?
EXTRA= .size() 和 .contains() 不会初始化整个集合
TRUE= 第一次访问时初始化整个集合
FALSE= 急切加载
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)