I would like to retrieve an object from my data store and upgrade its type. For instance from Employee
to ExtendedEmployee
defined below. Is it possible? How could I achieve this? Because of some synchronization issues in my project I cannot persist another copy of this object (remove actual and save extended one).
@Entity
@Table(name = "employee")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue(value="employee")
public class Employee {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
//setters and getters
}
@Entity
@DiscriminatorValue("extendedemployee")
public class ExtendedEmployee extends Employee{
@Column(name="salary")
private float salary;
@Column(name="bonus")
private int bonus;
//setters and getters
}