Thank you a lot. I have learned a lot form you answer and
https://vladmihalcea.com/how-to-optimize-unidirectional-collections-with-jpa-and-hibernate/, but I still don't kown how to solve my problem.
Can you post a example or give relevent materials that I can get a list of "ChapterEntity", and lists of "ChapterTitle1Entity" obder by "ChapterTitle1Entity.sequence" desc in each ChapterEntity. Thanks again!
the following is my ChapterEntity.java and ChapterTitle1Entity.java files:
ChapterEntity.java
Code:
@Entity
@Table(name = "chapter")
public class ChapterEntity {
private List<ChapterTitle1Entity> chapterTitle1EntityList;
private long id;
private int sequence;
private String content;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "chapterEntity")
@Fetch(FetchMode.SUBSELECT)
public List<ChapterTitle1Entity> getChapterTitle1EntityList() {
return chapterTitle1EntityList;
}
public void setChapterTitle1EntityList(List<ChapterTitle1Entity> chapterTitle1EntityList) {
this.chapterTitle1EntityList = chapterTitle1EntityList;
}
......
}
ChapterTitle1Entity.java
Code:
@Entity
@Table(name = "chapter_title_1", schema = "tutorial2")
public class ChapterTitle1Entity {
private long id;
private int sequence;
private String content;
private int type;
private ChapterEntity chapterEntity;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "chapter_id", nullable = false)
public ChapterEntity getChapterEntity() {
return chapterEntity;
}
public void setChapterEntity(ChapterEntity chapterEntity) {
this.chapterEntity = chapterEntity;
}
@Basic
@Column(name = "sequence", nullable = false)
public int getSequence() {
return sequence;
}
......
}