I have a class called Coach, that has an attribute of type Person. The person class has an attribute called id. Inside of the Coach table in the database, a field, id, is used as the primary key, which corresponds to the id of the person. How do I specify the @id for the Coach class, using annotations?
Well, a coach is a person, so there is a person table that has an id field, first name, and last name.
@Entity
@Table(name="COACH_TABLE")
public class Coach {
@OneToOne
@JoinColumn(name = "ID")
private Person person;
}
@Entity
@Table(name="PERSON_TABLE")
public class Person {
@Id
@Column(name="ID")
private int id;
}
I want to say that the @Id attribute for my Coach class is the id of the Person attribute.