There may be one-way or two-way relationships. When it is unidirectional only one class has the reference, which is the attribute, and this is noted.
@Entity
public class SystemUser {
@OneToOne
private Debt debt;
}
When Bidirectional the two classes have an attribute referencing each other.
@Entity
public class SystemUser {
@OneToOne
private Debt debt;
}
@Entity
public class Debt {
@OneToOne
@JoinColumn(mappedBy = "debt")
private SystemUser systemUser;
}
Adds the mappedBy attribute on the non-dominant side. In class Systemuser has a Debt attribute, this is the name that will be used for mappedBy.
If the mappedBy attribute was not used, two relationships would be created between Systemuser and Debt. Each relationship with a dominant side.
Take Care of Bi-Directional Relationships. Look For More About Them.