DB Table:
Employee Table
ID, Type, Salary, Rate
Type can be full time or contractor. And full time has attribute of salary, contractor has attribute of rate. (I know it's not normalized. But it's what it is. Appreciate it if you can educate me why it's a bad design)
JPA Class: (Oracle JPA)
@Entity
@Table(name="Employee")
public abstract class Employee{...}
@Entity
public class FullTimeEmployee extends Employee{...}
public class EmployeeService{
...
Employee joe = entityManager.find(Employee.class, id);
((FullTimeEmployee) joe).getSalary(); //Can I do this?
//Or I have to use Employee joe = entityManager.find(FullTimeEmployee.class, id);
...
}
Can I downcast a entity class this way? Thanks!
Edit:
My other concerns are this. Both 2 types of employee was stored in the same table. So how come entityManager.find(Employee.class, id) know that which id is fulltime?
So, does it make a difference if I did
entityManager.persist((Employee)fullTimeEmp);
instead of
entityManager.persist(fullTimeEmp);