gpt4 book ai didi

java - Hibernate @LazyCollection 注解有什么用

转载 作者:IT老高 更新时间:2023-10-28 21:11:35 25 4
gpt4 key购买 nike

我有 2 个实体作为 Parent 和 Child 作为 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 = 急于加载

关于java - Hibernate @LazyCollection 注解有什么用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928402/

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