0 votes
in JAVA by
Which are the Different Types of Relationships Available in Hibernate Mapping?

1 Answer

0 votes
by
There are three different types of relationships that can be implemented in hibernate. They are:

One to One Mapping

It represents the ONE-TO-ONE relationship between two tables.

For example, we create Instructor and InstructorDetail entities and we make a one-to-one mapping between them.

One to Many Mapping

It represents the ONE-TO-MANY relationships between two tables. The one-to-many mapping means that one row in a table is mapped to multiple rows in another table.

For example, consider the following two tables - posts and comments of a Blog database schema where the posts table has a one-to-many relationship with the comments table:

Many to One Mapping

It represents the one-to-many or many-to-one relationships between two tables.

For example, consider the following relationship between the Student and Address entity.

According to the relationship, many students can have the same address.

Many to Many Mapping

It represents the many to many relationships between two tables.

For example, consider the following tables where employees and projects exhibit a many-to-many relationship with each other -

The many-to-many relationship is implemented using a third table called employees_projects which contains the details of the employees and their associated projects. Note that here Employee is a primary entity.

Related questions

+1 vote
asked May 25, 2020 in JAVA by Robindeniel
0 votes
asked Oct 5, 2023 in Service Now by john ganales
...