JPA Table-per-class StrategyIn table-per-class strategy, for each sub entity class a separate table is generated. Unlike joined strategy, no separate table is generated for parent entity class in table-per-class strategy. The following syntax represents the table-per-class strategy: - Table-per-class ExampleIn this example, we will categorize employees into active employees and retired employees. Thus, the subclass ActiveEmployees and RetiredEmployees inherits the e_id and e_name fields of parent class Employee. Now, follow the below steps to create JPA project,
Employee.java
ActiveEmployee.java
RetiredEmployee.java
Persistence.xml
EmployeePersistence.java Output: After the execution of the program, two tables are generated in MySQL workbench. Now, fetch data from each table separately to generate the output.
![]()
![]()
Next Topic#
|