I want to use inheritance or some clean JPA logic so that i dont have to replicate my code to perform POST, GET and PUT operations on 2 identical table objects using spring data jpa
I have 2 identical tables as 1) contractemployees 2)permanentemployees
Both have the same structure
CREATE TABLE permanentemployee (
empid int(11) NOT NULL,
age int(11) NOT NULL,
departmentname varchar(255) NOT NULL,
empname varchar(255) DEFAULT NULL,
salary int(11) NOT NULL,
PRIMARY KEY (empid));
CREATE TABLE contractemployees(
empid int(11) NOT NULL,
age int(11) NOT NULL,
departmentname varchar(255) NOT NULL,
empname varchar(255) DEFAULT NULL,
salary int(11) NOT NULL,
PRIMARY KEY (empid));
PROBLEM I want to use a single spring data JPA Repo which can create, get, update the records.
Adding all the table properties to a abstract class entity
@Entity
@MappedSuperclass
@Data
public abstract class Employee{
private String empname;
private String departmentid;
private int age;
private int salary;
}
First entity for contract employees
@Entity
@Table(name="contractemployee")
public class Contractemployees extends Employee {
@Id
private int empid;
}
Second entity for permananent employees
@Entity
@Table(name="permanentemployee")
public class PermanentEmployee extends Employee {
@Id
private int empid;
}
Repo
@NoRepositoryBean
public interface EmployeeRepo<T extends Employee> extends CrudRepository<T, Integer> {
}
How should i pass these object from controller that JPA knows which table to fetch/update from.