There may be a Unidirectional or Bidirectional relationship. 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 it is 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 the SystemUser class has a debt attribute, this is the name that will be used for mappedBy.
If you did not use the mappedBy attribute, you would create two relationships between SystemUser and Debt. Each relationship with a dominant side.
Watch out for two-way relationships. Look for more about them.