1)PFB the link reference for basic spring boot projects and concepts,
2)In a one-to-many relationship, one record in a table can be associated with one or more records in another table.
2.1)It helps to link with 2 tables contains primary key and foreign key.
2.2)@OneToMany annotation automatically creates the foreign key in child table and represents the link between 2 tables.
2.3)It ensures the link between parent table having one data has linked with child table having one or more data.
Parent Table:
3)PFB the One-To-Many from code perspective,
3.1)This base entity is an abstract class and it only contains common parameters for all tables.
3.2)EmpModel class denoted here as parent model class3.3)EmpExpModel class denoted has child model class
3.4)@JsonManagedReference and @JsonBackReference annotations are helps to prevents from data duplication issue.
4)This project explains below using Spring Boot, Restful-web-service and JPA,
- Save or Update single data in all 2 tables against single data from request on One-To-Many Mapping.
- Save or Update multiple data in all 2 tables against multiple data from request on One-To-Many Mapping.
- Fetch single data from 2 tables against single data from request on One-To-Many Mapping.
- Fetch multiple data from 2 tables against multiple data from request on One-To-Many Mapping.
- Fetch all data from 2 tables on One-To-Many Mapping.
- Fetch all data from child table on One-To-Many Mapping.
- Fetch single data from child table against single data from request on One-To-Many Mapping.
- Fetch multiple data from child table against multiple data from request on One-To-Many Mapping.
- Save or Update single data in child table against single data from request on One-To-Many Mapping.
- Save or Update multiple data in child table against multiple data from request on One-To-Many Mapping.
5)Use the below link to download the source code,
Previous session: Click to know - One-To-One mapping using Spring boot - Beginners
Context page: Click here
Home page: Click here
Thanks, I hope you enjoyed this session !!!.
-Somasundar Kanakaraj