我有以下UML图。
由于它是manyToMany关系,我需要三个表来存储数据:
CREATE TABLE Users(
idObj BIGINT NOT NULL PRIMARY KEY,
nome VARCHAR(100),
nomeUtente VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL
);
CREATE TABLE Works(
idObj BIGINT NOT NULL PRIMARY KEY,
nrIncarico int,
annoIncarico int,
...
);
CREATE TABLE UsersWorksRel(
idGiudice BIGINT NOT NULL,
idIncarico BIGINT NOT NULL,
FOREIGN KEY (idGiudice) REFERENCES Users(idObj),
FOREIGN KEY (idIncarico) REFERENCES Works(idObj)
);
在AbstractPO中,我使用了@MappedSuperclass
注释,用户也没问题,但是我无法注释Judge类......
我的想法是使用Judge类与Works具有manyToMany关系,如下所示:
public class Judge extends UserPO{
private List<Works> incarichi;
public Judge () {
setTipo(TipologiaUtente.GIUDICE);
}
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "UsersWorksRel", joinColumns = {
@JoinColumn(name = "idGiudice", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "idIncarico", nullable = false, updatable = false) })
public List<Works> getIncarichi() {
return incarichi;
}
public void setIncarichi(List<Works> incarichi) {
this.incarichi = incarichi;
}
}