user12080466
user12080466

Reputation:

Why we need a list as property in the entity classes of a one to many relationship in hibernate?

enter image description here

                                   EER Diagram

My question is that why we need to have a list in the one to many relationship ,because for an example if you have a relationship of one to many between Instructor and Course classes[one instructor can teach many courses,but one course has only one instructor] why we need to have a list of courses in instructor class.I mean I already saved both instructor and course data to mysql database with the aid of the foreign key in course class.So why still we need that property of list ?

Course model class the property of private Instructor instructorId with the annotations of @ManyToOne,@JoinColoumn

*Please note that instructorDetail class is not related to this question.

Upvotes: 1

Views: 364

Answers (1)

Dragolis
Dragolis

Reputation: 66

You do not have to include that list, and it wouldn't change the database structure under the hood. Having that list is only for comfort, enabling you to execute queries using the courses list of an instructor.

Upvotes: 1

Related Questions