title: Hibernate Relationship Mapping structure
body: <p>Hello I am wondering how can i use relationship mappings in order to map all the tables (Player, Referee, Competition) into table (Score).
  Should i use only OneToOne relationships?</p>
  <p>ManyToMany relations create another table, but I want everything to be mapped into Score table, because I have everything there.</p>
  <p>Should I reprogram my mysql database or is it OK?</p>
  <pre class="lang-java prettyprint-override"><code>package com.simon.MavenHibernateProject;
  
  imports..
  
  @Entity
  @Table(name = &quot;player&quot;)
  public class Player implements Serializable{
      private static final long serialVersionUID = 1L;
      
      @Id
      @Column(name = &quot;p_id&quot;, unique = true)
      private int p_id;
      
      @Column(name = &quot;firstName&quot;, nullable = false)
      private String fName;
      
      @Column(name = &quot;lastName&quot;, nullable = false)
      private String lName;
      
      @Column(name = &quot;phone&quot;, nullable = false)
      private String phone;
  
      @Column(name = &quot;address&quot;, nullable = false)
      private String address;
      
  
      getters, setters...
      
  }
  
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>package com.simon.MavenHibernateProject;
  
  imports...
  
  @Entity
  @Table(name = &quot;referee&quot;)
  public class Referee implements Serializable{
      private static final long serialVersionUID = 1L;
      
      @Id
      @Column(name = &quot;r_id&quot;, unique = true)
      private int r_id;
      
      @Column(name = &quot;firstName&quot;, nullable = false)
      private String fName;
      
      @Column(name = &quot;lastName&quot;, nullable = false)
      private String lName;
      
      @Column(name = &quot;phone&quot;, nullable = false)
      private String phone;
  
      @Column(name = &quot;address&quot;, nullable = false)
      private String address;
      
      getters, setters...
      
  }
  
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>package com.simon.MavenHibernateProject;
  
  imports...
  
  @Entity
  @Table(name = &quot;competition&quot;)
  public class Competition implements Serializable {
      private static final long serialVersionUID = 1L;
      
      @Id
      @Column(name = &quot;comp_id&quot;, unique = true)
      private int comp_id;
  
      @Column(name = &quot;discipline&quot;, nullable = false)
      private String discipline;
      
      @Column(name = &quot;category&quot;, nullable = false)
      private String category;
      
      @Column(name = &quot;data&quot;, nullable = false)
      private Date data;
  
      @Column(name = &quot;city&quot;, nullable = false)
      private String city;
      
      @Column(name = &quot;country&quot;, nullable = false)
      private String country;
      
      getters, setters...
  }
  
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>package com.simon.MavenHibernateProject;
  
  imports...
  
  @Entity
  @Table(name = &quot;score&quot;)
  public class Score implements Serializable{
      private static final long serialVersionUID = 1L;
  
      @Id
      @Column(name = &quot;score_id&quot;, unique = true)
      private int score_id;
  
      @Column(name = &quot;comp_id&quot;, nullable = false)
      private int comp_id;
      
      @Column(name = &quot;r_id&quot;, nullable = false)
      private int r_id;
      
      @Column(name = &quot;p_id&quot;, nullable = false)
      private int p_id;
  
      @Column(name = &quot;points&quot;, nullable = false)
      private float points;
      
      getters, setters...
          
  }
  
  </code></pre>
  <p>Mysql :</p>
  <pre class="lang-sql prettyprint-override"><code>create table player(
      p_id INT PRIMARY KEY,
      firstName VARCHAR(30) NOT NULL,
      lastName VARCHAR(30) NOT NULL,
      phone VARCHAR(30) NOT NULL,
      address VARCHAR(30) NOT NULL);
      
  create table referee(
      r_id INT PRIMARY KEY,
      firstName VARCHAR(30) NOT NULL,
      lastName VARCHAR(30) NOT NULL,
      phone VARCHAR(30) NOT NULL,
      address VARCHAR(30) NOT NULL);
      
  create table competition(
      comp_id INT PRIMARY KEY,
      discipline VARCHAR(30) NOT NULL,
      category VARCHAR(30) NOT NULL,
      data DATETIME NOT NULL,
      city VARCHAR(30) NOT NULL,
      country VARCHAR(30) NOT NULL);
      
  create table score(
      score_id INT PRIMARY KEY,
      comp_id INT, 
      r_id INT,
      p_id INT,
      points FLOAT,
      FOREIGN KEY (comp_id) REFERENCES competition(comp_id),
      FOREIGN KEY (r_id) REFERENCES referee(r_id),
      FOREIGN KEY (p_id) REFERENCES player(p_id));
  </code></pre>