I have a class Person with two subclasses Student and Employee
@Entity(name="person")
@Inheritance(strategy = InheritanceType.JOINED)
public class Person implements Serializable {
@Id
@GeneratedValue
private Integer id;
}
@Entity(name="student")
@PrimaryKeyJoinColumn(name="id")
public class Student extends Pessoa implements Serializable {
}
@Entity(name="employee")
@PrimaryKeyJoinColumn(name="id")
public class Employee extends Person implements Serializable {
}
Run Code Online (Sandbox Code Playgroud)
A student can also be an employee, but when I try to save a student with the same id as an employee, hibernate throws a duplicate primary key exception
org.hibernate.exception.ConstraintViolationException: Duplicate …Run Code Online (Sandbox Code Playgroud)