JPA Single Table StrategyThe single table strategy is one of the most simplest and efficient way to define the implementation of inheritance. In this approach, instances of the multiple entity classes are stored as attributes in a single table only. The following syntax represents the single table strategy: - Single Table Strategy 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, run select * from employee_details query in MySQL database to generate the following output: - ![]()
Next TopicJPA Joined strategy
|