Hibernate @LazyCollection注解的用处是什么? [英] What is the use of the Hibernate @LazyCollection annotation
本文介绍了Hibernate @LazyCollection注解的用处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个实体作为Parent和Child作为OneToMany关系作为
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
私人字符串名称;
@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),它会在什么时候出现在图片中,比如哪个子列表的操作,会有好处?
解决方案
为了给你一个提示,主要是出于性能原因,你可以开始阅读以下链接:
<第二级缓存
I have 2 entities as Parent and Child as OneToMany relation as
@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
}
So here what is use of @LazyCollection(LazyCollectionOption.EXTRA) and when does it will come in picture, like for which operation with child list, it will be beneficial ?
解决方案
To give you a hint, it's mainly for performance reasons, you can start reading the following links:
这篇关于Hibernate @LazyCollection注解的用处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文