I am newbie to UML diagrams and would like to code the following one, where there is an OneToOne double bidirectional association, with JPA annotations.

Context: there are persons and teams. Each team is composed of persons and each person can only belong to one team. The teams have always a person acting as main Leader and optionally can have a second Leader.
Based on this page, I have written the code below but I am not sure if it is right.
@Entity
public class Person extends BaseEntity {
...
@NotNull
@OneToOne(mappedBy="mainLeader", cascade = CascadeType.ALL, orphanRemoval = true)
private Team mainTeam;
@NotNull
@OneToOne(mappedBy="secondLeader", cascade = CascadeType.ALL, orphanRemoval = true)
private Team secondTeam;
}
@Entity
public class Team extends BaseEntity {
...
@NotNull
@OneToOne
private Person mainLeader;
@OneToOne
private Person secondLeader;
}
The association names suggests roles to be used. Main Leader might correspond to a role mainLeader. So I would just create a property in Team.
But since the associations are just named and do not have roles you are open to create roles at wish. This should be derived from the context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With