By: Henry

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

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

The Student Entity:

@OneToMany(cascade = CascadeType.ALL,
      fetch = FetchType.LAZY,
      mappedBy = "student")
private List courseList = new ArrayList<>();

And the Course entity:

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "STUDENT_ID", nullable = false)
private Student student;

I thought in the Course entity, the inverse annotation would be a @ManyToOne but I found a @OneToOne. 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教學網站, 熱門新聞 並標籤為 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 。將永久鏈結加入書籤。