How is the “Own Side" of this many-to-many relationship determined?

I am trying to strengthen my understanding of the Owning-side concept. Could not get a clear picture from any question I found here. I mainly look at the Java EE JPA tutorial. They have the following database schema, where PLAYERthey TEAMare many-to-many

enter image description here


Also indicated

  • A player can be on many teams.
  • A team can have many players.
  • Between PLAYERand TEAMthere is a relationship "many-to-many".

Pretty far ahead. But when it comes to the coding part, they make the TEAMowner 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. I can not process:

1. , TEAM -?

2. , PLAYER ?

.

", @JoinTable, TEAM PLAYER.

:

3. ? , , , , @JoinTable?

+3
3
  • , TEAM -?

ManytoMany , , , , , . , ManyToOne.

  1. , PLAYER ?

, , .

  1. ? , , , , @JoinTable?

, @JoinTable . .

Cascade, , , .

+3

AFAIK . - m: n.

, :

  • , TEAM -?

-, .

2. , PLAYER , , ?

3. ? , , , , @JoinTable?

+2

ManyToMany. ,

1

  • According to the design of the database, it is determined that TEAM is the owner.

For question 2

  • It makes no difference if PLAYER were instead of this scenario. Check out this documentation .

For question 3

  • It depends on the design of your database.
+1
source

All Articles