How do we achieve unidirectional @OneToOne Mapping between two entities with @JoinColumn to apply on target entity.
For E.g. I have two entities:
@Entity
public class Person {
// Attaches column in the source entity i.e. Person
@OneToOne
@JoinColumn(name = "Person_ID")
private Address address;
//Works for @oneToMany, attaches column in target entity i.e. Address
@OneToMany
@JoinColumn(name = "Person_ID")
private Set<Address> addresses;
}
@Entity
public class Address {
//list of columns
}
As per documentation: http://docs.oracle.com/javaee/6/api/javax/persistence/JoinColumn.html
If the join is for a OneToOne or ManyToOne mapping using a foreign key mapping strategy, the foreign key column is in the table of the source entity or embeddable.
If the join is for a unidirectional OneToMany mapping using a foreign key mapping strategy, the foreign key is in the table of the target entity.