Skip to main content

Mapping - Many-to-One & Many-to-Many

Learn Mapping - Many-to-One & Many-to-Many (Spring Data JPA, Spring Boot) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

1. Many-to-One Mapping Many-to-one means that multiple rows in a table can be mapped to a single row in another table. Example: many employees have one address. Business requirement: save many employee details with one address into the database. Problem statement: design the REST API to save multiple employees with one address. Table structure Many-to-one is simply the other end of a one-to-many . The same foreign key column, address_id , serves both views: @ManyToOne on Employee owns it, @OneToMany(mappedBy = "address") on Address reads it.

More lessons in Spring Data JPA