I\'m using Spring with Hibernate as a JPA provider and are trying to get a @OneToMany (a contact having many phonenumbers) to save the foreign key in the phone numbers table
If the Contact-Phone relationship is unidirectional, you can also replace mappedBy in @OneToMany annotation with @JoinColumn(name = "contact_id").
@Entity
public class Contact {
@Id
private Long id;
@OneToMany(cascade = CascadeType.PERSIST)
@JoinColumn(name = "contact_id")
private List phoneNumbers;
// normal getter/setter
...
}
@Entity
public class PhoneNumber {
@Id
private Long id;
...
}
Similar in JPA @OneToMany -> Parent - Child Reference (Foreign Key)