I'm trying to get a firm grasp on the concept of Owning-side. Couldn't really get a clear picture from any question i found here. Basically I'm going through the Java EE JPA tutorial. They have the following database schema, where PLAYER
and TEAM
have a many-to-many relationship
Also stated
- A player can be on many teams.
- A team can have many players.
- There is a many-to-many relationship between
PLAYER
andTEAM
.
Pretty straight forward so far. But when is gets to the coding part, they make the TEAM
the owning side of the relationship.
public class Team {
private Collection<Player> players;
@ManyToMany
@JoinTable(
name = "PERSITENCE_ROSTER_TEAM_PLAYER",
joinColumns = @JoinColumn(name = "TEAM_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "PLAYER_ID", referencedColumnName = "ID")
)
public Collection<Player> getPlayers() {
return players;
}
}
public class Player {
private Collection<Team> teams;
@ManyToMany(mappedBy = "players")
public Collection<Team> getTeams() {
return teams;
}
}
Question(s)
I have no problem understanding the code. What I can't get a handle on is:
1. How is it determined that
TEAM
is the owning side?2. Would it make any difference if
PLAYER
was made the owning side instead, in this scenario?
Also stated from the tutorial.
"The entity that specifies the
@JoinTable
is the owner of the relationship, so theTEAM
entity is the owner of the relationship with thePLAYER
entity."
That being said:
3. Would the above statement make my second question true? Meaning that there is no determining factor besides which one you decide to make the owning side, with the
@JoinTable
annotation?