作者彙整:Henry

By: Henry

Hi Vlad, thanks for your blogs on JPA and Hibernate.

In my codebase, I found a <code>Student</code> and <code>Course</code> entity classes with the below relationships.

The <code>Student</code> Entity:

[code lang=”java”]
@OneToMany(cascade = CascadeType.ALL,
fetch = FetchType.LAZY,
mappedBy = “student”)
private List courseList = new ArrayList<>();
[/code]

And the <code>Course</code> entity:

[code lang=”java”]
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = “STUDENT_ID”, nullable = false)
private Student student;
[/code]

I thought in the <code>Course</code> entity, the inverse annotation would be a <code>@ManyToOne</code> but I found a <code>@OneToOne</code>. Is this possible given your statement in one of your article:

“The bidirectional association requires the child entity mapping to provide a @ManyToOne annotation, which is responsible for controlling the association.”

Thanks 繼續閱讀

發表於 IT 資訊科技(信息技术), java 1 對 1 私人補習, java教學網站, 熱門新聞 | 已標籤 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | 在〈By: Henry〉中留言功能已關閉