Skip to main content

Discuss about the relationships in HIBERNATE


 


Let's discuss about the @One-To-One, @One-To-Many, @Many-To-One,

@Many-To-Many annotations in hibernate these are used to define the relationships between entities in the Java application and the corresponding tables in the relational database.


⭐ @One-To-One:

👉 Represents a one-to-one relationship between two entities.

👉 It is used when each record in one table corresponds to exactly one record in another table.

👉 example: a person can only have one Aadhar Card.


⭐ @One-To-Many:

👉 Represents a one-to-many relationship between two entities.

👉 It is used when each record in one table can have multiple related records in another table.

👉 example: one department can have many employees.


⭐ @Many-To-One:

👉 Represents a many-to-one relationship between two entities.

👉 It is used when multiple records in one table can be associated with a single record in another table.

👉 example: multiple orders can associated with one customer.


⭐ @Many-To-Many :

👉 Represents a many-to-many relationship between two entities.

👉 It is used when each record in one table can be associated with multiple records in another table, and vice versa.

👉 example: multiple students can enroll multiple courses.

Comments