Здравствуйте, мне интересно, как я могу использовать сопоставление отношений, чтобы сопоставить все таблицы (Игрок, Рефери, Соревнование) в таблице (Оценка). Должен ли я использовать только отношения OneToOne?
Отношения ManyToMany создают другую таблицу, но я хочу, чтобы все было отображено в таблице Score, потому что у меня там все есть.
Следует ли мне перепрограммировать мою mysql базу данных или все в порядке?
package com.simon.MavenHibernateProject;
imports..
@Entity
@Table(name = "player")
public class Player implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "p_id", unique = true)
private int p_id;
@Column(name = "firstName", nullable = false)
private String fName;
@Column(name = "lastName", nullable = false)
private String lName;
@Column(name = "phone", nullable = false)
private String phone;
@Column(name = "address", nullable = false)
private String address;
getters, setters...
}
package com.simon.MavenHibernateProject;
imports...
@Entity
@Table(name = "referee")
public class Referee implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "r_id", unique = true)
private int r_id;
@Column(name = "firstName", nullable = false)
private String fName;
@Column(name = "lastName", nullable = false)
private String lName;
@Column(name = "phone", nullable = false)
private String phone;
@Column(name = "address", nullable = false)
private String address;
getters, setters...
}
package com.simon.MavenHibernateProject;
imports...
@Entity
@Table(name = "competition")
public class Competition implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "comp_id", unique = true)
private int comp_id;
@Column(name = "discipline", nullable = false)
private String discipline;
@Column(name = "category", nullable = false)
private String category;
@Column(name = "data", nullable = false)
private Date data;
@Column(name = "city", nullable = false)
private String city;
@Column(name = "country", nullable = false)
private String country;
getters, setters...
}
package com.simon.MavenHibernateProject;
imports...
@Entity
@Table(name = "score")
public class Score implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "score_id", unique = true)
private int score_id;
@Column(name = "comp_id", nullable = false)
private int comp_id;
@Column(name = "r_id", nullable = false)
private int r_id;
@Column(name = "p_id", nullable = false)
private int p_id;
@Column(name = "points", nullable = false)
private float points;
getters, setters...
}
Mysql:
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));