JPA Cascade Persist
The cascade persist is used to specify that if an entity is persisted then all its associated child entities will also be persisted. The following syntax is used to perform cascade persist operation: -
JPA Cascade Persist Example
In this example, we will create two entity classes that are related to each other but to establish the dependency between them we will perform cascading operation.
This example contains the following steps: -
Note - The primary key in student table i.e s_id will treat as a foreign key in subject table to maintain a relationship between both the tables.
After the execution of the program, the following tables are generated under MySQL workbench.