One-to-Many
Many-to-One
One-to-One
Many-to-Many
Let's tackle these relationships one by one.
One-to-Many/Many-to-One
We'll get started with the One-to-Many and Many-to-One relationships, which are closely related. You could go ahead and say that they're the opposite sides of the same coin.
What's a One-to-Many relationship?
As its name implies, it's a relationship that links one entity to many other entities.
In our example, this would be a Teacher and their Courses. A teacher can give multiple courses, but a course is given by only one teacher (that's the Many-to-One perspective - many courses to one teacher).
Another example could be on social media - a photo can have many comments, but each of those comments belongs to that one photo.
Before diving into the details of how to map this relationship, let's create our entities:
https://stackabuse.com/a-guide-to-jpa-with-hibernate-relationship-mapping/