Let us say a class/entity named student which contains an id, father's occupation and mother's occupation and the entity classes are like this
Student class
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true, updatable = false)
private int id;
@OneToOne
@JoinColumn(name = "occupationId")
Occupation fathersOccupation;
@OneToOne
@JoinColumn(name = "occupationId")
Occupation mothersOccupation;
}
and the Occupation class
@Entity
@Table(name = "occupation")
public class Occupation {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "occupationId")
int occupationId;
@Column
String title;
}
When I tried @OneToOne mapping for both father's occupation and mother's occupation it is throwing exception,Repeated column in mapping for entity. I tried adding @Column(name="<columnName>"), but it is not allowed. I really want those two fields,fathersOccupation and mothersOccupation with oneToOne mapping in the student table.