Advertisement

Google Ad Slot: content-top

Spring Boot Relationship Mappings


Spring Boot with JPA provides various relationship mappings to define associations between entities using annotations. These relationships correspond to SQL JOIN operations.


Types of Relationship Mappings:

Relationship Type

Description

Example

One-to-One (@OneToOne)


One entity has exactly one related entity.

User has oneProfile.

One-to-Many (@OneToMany)

One entity has multiple related entities.

Department has manyEmployees.

Many-to-One (@ManyToOne)

Many entities are related to one entity.


Many Employees belong to oneDepartment.


Many-to-Many (@ManyToMany)

Many entities are related to many entities.

Many Students enroll in manyCourses.