There are two errors in your code.
First, you annotated the getter in Person, and annotated the field in its subclass Doctor. That's why you get this error: once Hibernate sees the @Id
annotation on a getter in the base class, it only considers annotations on getters in the rest of the class hierarchy, and ignores the annotations on fields.
Second, your OneToOne bidirectional association is mapped incorrectly. One side must always be the inverse side in a bidirectional association. So, the following field:
@OneToOne
private Doctor doctor;
should be
@OneToOne(mappedBy = "specialty")
private Doctor doctor;
to inform JPA that the Specialty.doctor
association is the inverse side of the OneToOne association already declared and mapped in Doctor.specialty
.