Assume I have two classic non-abstract JPA classes: Person and Student.
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String id;
// ...
}
@Entity
public class Student extends Person {
// ...
}
Now person having some id enters the university and becomes a student. How do I process that fact in JPA and keep person's id?
student = new Student();
student.setPersonData(person.getPersonData());
student.setId(person.getId());
entityManager.persist(student);
Code above produces 'Detached entity passed to persist' Exception, whereas using entityManager.merge(student) skips assigned id and creates two new entities of Person and Student with new id. Any ideas how can I keep original Id?